Skip to content

Instantly share code, notes, and snippets.

@philcon93
Created October 4, 2017 02:57
Show Gist options
  • Save philcon93/a3ad3139d432f28549029be85d2d9a48 to your computer and use it in GitHub Desktop.
Save philcon93/a3ad3139d432f28549029be85d2d9a48 to your computer and use it in GitHub Desktop.
Quick jQuery Validation

jQuery Validation

JS

	<script type="text/javascript" src="[%ntheme_asset%]js/jquery-validation/jquery.validation.min.js[%/ntheme_asset%]"></script>
	<script type="text/javascript" language="javascript">
		$("#register").validate({
			rules: {
				reg_email: {
					required: true,
					email: true
				},
				reg_password: {
					required: true,
					abcPassword: true,
					minlength: 9
				},
				reg_password2: {
					required: true,
					abcPassword: true,
					minlength: 9,
					equalTo: "#reg_password"
				}
			}
		});
		jQuery.validator.addMethod("abcPassword", function(value, element) {
			return this.optional( element ) || /[a-z]/.test(value) && /[0-9]/.test(value) && /[A-Z]/.test(value);
	  }, 'Please enter a valid password with at least one number, one uppercase letter.');
	</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment