Snippets Collections
import imghdr
import os
from flask import Flask, render_template, request, redirect, url_for, abort, \
    send_from_directory
from werkzeug.utils import secure_filename

app = Flask(__name__)
app.config['MAX_CONTENT_LENGTH'] = 2 * 1024 * 1024
app.config['UPLOAD_EXTENSIONS'] = ['.jpg', '.png', '.gif']
app.config['UPLOAD_PATH'] = 'uploads'

def validate_image(stream):
    header = stream.read(512)
    stream.seek(0)
    format = imghdr.what(None, header)
    if not format:
        return None
    return '.' + (format if format != 'jpeg' else 'jpg')

@app.errorhandler(413)
def too_large(e):
    return "File is too large", 413

@app.route('/')
def index():
    files = os.listdir(app.config['UPLOAD_PATH'])
    return render_template('index.html', files=files)

@app.route('/', methods=['POST'])
def upload_files():
    uploaded_file = request.files['file']
    filename = secure_filename(uploaded_file.filename)
    if filename != '':
        file_ext = os.path.splitext(filename)[1]
        if file_ext not in app.config['UPLOAD_EXTENSIONS'] or \
                file_ext != validate_image(uploaded_file.stream):
            return "Invalid image", 400
        uploaded_file.save(os.path.join(app.config['UPLOAD_PATH'], filename))
    return '', 204

@app.route('/uploads/<filename>')
def upload(filename):
    return send_from_directory(app.config['UPLOAD_PATH'], filename)
        if file_ext not in app.config['UPLOAD_EXTENSIONS'] or \
                file_ext != validate_image(uploaded_file.stream):
            return "Invalid image", 400
@app.errorhandler(413)
def too_large(e):
    return "File is too large", 413
import imghdr
import os
from flask import Flask, render_template, request, redirect, url_for, abort, \
    send_from_directory
from werkzeug.utils import secure_filename

app = Flask(__name__)
app.config['MAX_CONTENT_LENGTH'] = 1024 * 1024
app.config['UPLOAD_EXTENSIONS'] = ['.jpg', '.png', '.gif']
app.config['UPLOAD_PATH'] = 'uploads'

def validate_image(stream):
    header = stream.read(512)  # 512 bytes should be enough for a header check
    stream.seek(0)  # reset stream pointer
    format = imghdr.what(None, header)
    if not format:
        return None
    return '.' + (format if format != 'jpeg' else 'jpg')

@app.route('/')
def index():
    files = os.listdir(app.config['UPLOAD_PATH'])
    return render_template('index.html', files=files)

@app.route('/', methods=['POST'])
def upload_files():
    uploaded_file = request.files['file']
    filename = secure_filename(uploaded_file.filename)
    if filename != '':
        file_ext = os.path.splitext(filename)[1]
        if file_ext not in app.config['UPLOAD_EXTENSIONS'] or \
                file_ext != validate_image(uploaded_file.stream):
            abort(400)
        uploaded_file.save(os.path.join(app.config['UPLOAD_PATH'], filename))
    return redirect(url_for('index'))

@app.route('/uploads/<filename>')
def upload(filename):
    return send_from_directory(app.config['UPLOAD_PATH'], filename)
import imghdr
import os
from flask import Flask, render_template, request, redirect, url_for, abort
from werkzeug.utils import secure_filename

app = Flask(__name__)
app.config['MAX_CONTENT_LENGTH'] = 1024 * 1024
app.config['UPLOAD_EXTENSIONS'] = ['.jpg', '.png', '.gif']
app.config['UPLOAD_PATH'] = 'uploads'

def validate_image(stream):
    header = stream.read(512)
    stream.seek(0) 
    format = imghdr.what(None, header)
    if not format:
        return None
    return '.' + (format if format != 'jpeg' else 'jpg')

@app.route('/')
def index():
    return render_template('index.html')

@app.route('/', methods=['POST'])
def upload_files():
    uploaded_file = request.files['file']
    filename = secure_filename(uploaded_file.filename)
    if filename != '':
        file_ext = os.path.splitext(filename)[1]
        if file_ext not in app.config['UPLOAD_EXTENSIONS'] or \
                file_ext != validate_image(uploaded_file.stream):
            abort(400)
        uploaded_file.save(os.path.join(app.config['UPLOAD_PATH'], filename))
    return redirect(url_for('index'))
import imghdr

def validate_image(stream):
    header = stream.read(512)
    stream.seek(0)
    format = imghdr.what(None, header)
    if not format:
        return None
    return '.' + (format if format != 'jpeg' else 'jpg')
If(
    Len(TextInput.Text) = 11,
    RGBA(
        0,
        18,
        107,
        1
    ),
    Color.Red
)
DisplayMode= If(
    IsBlank(varName) Or IsBlank(varName) Or Len(TextInputBox.Text) < 11,
    DisplayMode.Disabled,
    DisplayMode.Edit
)


OnChange= Set(varName, Combobox.Selected) //Sets the variable to the combo box values or record

password: Yup.string()
          .required('Please Enter your password')
          .matches(
            /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})/,
            "Must Contain 8 Characters, One Uppercase, One Lowercase, One Number and One Special 			 			Case Character"),
            passwordConfirmation: Yup.string().oneOf(
              [Yup.ref("password"), null],
              "Passwords must match"
            ),
phone:yup
.string()
.min(11, "شماره وارد شده صحیح نیست")
.required("تلفن را وارد کنید")
.matches(/^[09].[0-9]{9}$/, "شماره تلفن خود را به درستی وارد کنید ")
username: yup
.string()
.min(3, "نام کاربری از 3 حرف کمتر نباشد")
.required("نام کاربری را وارد کنید")
.matches(
/^[A-za-zآابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهی]+/,
"نام کاربری را به درستی وارد کنید"
)
email: yup
.string()
.required("ایمیل را وارد کنید")
.matches(
/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\. [0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
        )
national_code: yup
      .string()
      .required("لطفا کد ملی خود را وارد کنید")
      .test("nationalCodeValid", "فرمت کد ملی صحیح نمی باشد", function (value) {
        if (!/^\d{10}$/.test(value)) return false;
        const check = +value[9];
        const sum =
          value
            .split("")
            .slice(0, 9)
            .reduce((acc, x, i) => acc + +x * (10 - i), 0) % 11;
        return sum < 2 ? check === sum : check + sum === 11;
      })
/*JS*/
const $form = $("{YOUR_FORM_CLASS}");
$.validator.addMethod("letters", function(e, a) {
		return this.optional(a) || e == e.match(/^[a-zA-Z\s]*$/);
	}),
	$form.validate({
		rules: {
			name: {
				required: !0,
				minlength: 2,
				maxlength: 45
			},
			countrycity: {
				required: !0
			},
			email: {
				required: !0,
				email: !0
			}
		},
		messages: {
			name: "Please specify your name",
			email: "Please specify a valid email address",
			countrycity: "Field cannot be blank"
		},
	});
/*JS*/
func isValid(testStr:String) -> Bool {
    guard testStr.count > 7, testStr.count < 18 else { return false }

    let predicateTest = NSPredicate(format: "SELF MATCHES %@", "^(([^ ]?)(^[a-zA-Z].*[a-zA-Z]$)([^ ]?))$")
    return predicateTest.evaluate(with: testStr)
}
/**
 * Verifies if passed URL (remote file or any webpage / webresource) exists
 * The check is implemented via method HEAD, so no data is downloaded anyway
 *
 * @param   <string> Remote URL to verify
 * @returns <bool>   Returns true if given URL exists, false otherwise
 */
function file_exists_remote (string $url) : bool
{
    $handle = curl_init();

    curl_setopt_array($handle, [
        CURLOPT_URL => $url,
        CURLOPT_SSL_VERIFYPEER => 0,
        CURLOPT_NOBODY => 1,
        CURLOPT_HEADER => 0,
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_FOLLOWLOCATION => 1,
        CURLOPT_AUTOREFERER => 1
    ]);

    curl_exec($handle);

    $responseCode = (int) curl_getinfo($handle, CURLINFO_RESPONSE_CODE);

    curl_close($handle);

    return $responseCode === 200;
}
/**
 * Provides quick & simple way to verify if some
 * string is valid URL
 *
 * @param   <string>  URL to verify
 * @returns <boolean> Returns true if passed string
 *                    is valid URL, false otherwise
 */
function validateUrl (url) {
    try {
        new URL(url)
    } catch (error) {
        return false
    }
  
    return true
}
/**
 * Provides strict e-mail address verification close to RFC
 * Includes support for unicode
 *
 * @param   <string>  E-mail address to verify
 * @returns <boolean> Returns true if e-mail address is considered to be valid,
 *                    false otherwise
 */

export default function validateEmail (email) {
    return typeof email === 'string' &&
        email &&
        email.length < 256 &&
        /^(?:[0-z!#$%&'*+/=?^_`{|}.~-]|[^\u0000-\u007F]){1,64}@(?:(?:[0-z-]|[^\u0000-\u007F]){1,62}\.)+(?:[0-z]|[^\u0000-\u007F]){2,63}$/i.test(email) &&
        !email.includes('..') &&
        !email.startsWith('.') &&
        !email.includes('.@') &&
        !email.includes('-.') &&
        !email.includes('.-')
}
star

Tue Sep 06 2022 14:21:28 GMT+0000 (UTC) https://blog.miguelgrinberg.com/post/handling-file-uploads-with-flask

#python #flask #validation #uploadfile
star

Tue Sep 06 2022 14:20:40 GMT+0000 (UTC) https://blog.miguelgrinberg.com/post/handling-file-uploads-with-flask

#python #validation #flask #uploadfile
star

Tue Sep 06 2022 14:19:49 GMT+0000 (UTC) https://blog.miguelgrinberg.com/post/handling-file-uploads-with-flask

#python #flask #validation
star

Tue Sep 06 2022 13:20:18 GMT+0000 (UTC) https://blog.miguelgrinberg.com/post/handling-file-uploads-with-flask

#python #flask #uploadfile #validation
star

Tue Sep 06 2022 13:13:22 GMT+0000 (UTC) https://blog.miguelgrinberg.com/post/handling-file-uploads-with-flask

#python #flask #uploadfile #validation
star

Tue Sep 06 2022 13:12:28 GMT+0000 (UTC) https://blog.miguelgrinberg.com/post/handling-file-uploads-with-flask

#python #flask #uploadfile #validation
star

Sun May 29 2022 07:12:48 GMT+0000 (UTC)

#yup #regex #validation
star

Mon Apr 25 2022 12:37:34 GMT+0000 (UTC)

#yup #regex #validation
star

Mon Apr 25 2022 12:36:27 GMT+0000 (UTC)

#yup #regex #validation
star

Mon Apr 25 2022 12:35:41 GMT+0000 (UTC)

#yup #regex #validation
star

Mon Apr 25 2022 12:33:53 GMT+0000 (UTC)

#yup #regex #validation
star

Sun Mar 20 2022 18:06:05 GMT+0000 (UTC)

#js #validation
star

Wed Mar 09 2022 08:36:25 GMT+0000 (UTC) https://stackoverflow.com/questions/55181606/how-to-have-a-firstname-validation-in-ios-swift4

#ios #swift #name #validation #validate
star

Sat Jan 08 2022 06:40:20 GMT+0000 (UTC) https://gist.github.com/juliyvchirkov/30337123712f345fab264516800d6302

#javascript #email #validation

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension