Created
January 18, 2016 01:09
-
-
Save dodangquan/2929f711a0ccfc4d83ad to your computer and use it in GitHub Desktop.
Form validate sử dụng jquery-validate plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by DangQuan on 16/1/2016. | |
*/ | |
$(document).ready( | |
function () { | |
$('.form-validate').validate( | |
{ | |
rules: { | |
"account.username": { | |
required: true, | |
minlength: 2, | |
remote: { | |
url: "/customer/account/check/user/available", | |
type: "get", | |
data: { | |
username: function () { | |
return $("#account.username").val(); | |
} | |
} | |
} | |
}, | |
"account.password": { | |
required: true, | |
minlength: 5 | |
}, | |
firstname: { | |
required: true, | |
minlength: 2 | |
}, | |
url: { | |
required: true, | |
url: true | |
}, | |
houseNumber: { | |
required: true | |
}, | |
"account.email": { | |
required: true, | |
minlength: 2, | |
email: true | |
}, | |
security_username: { | |
required: true, | |
minlength: 2 | |
}, | |
security_password: { | |
required: true, | |
minlength: 5 | |
}, | |
password_again: { | |
required: true, | |
minlength: 5, | |
equalTo: "#account.password" | |
} | |
}, | |
messages: { | |
password_again: { | |
required: "This field is required.", | |
minlength: "This field must contain at least 5 characters.", | |
equalTo: "Passwords do not match." | |
}, | |
"account.username": { | |
required: "This field is required.", | |
minlength: "This field must contain at least 2 characters.", | |
remote: "Such username already exists." | |
}, | |
"account.email": { | |
required: "This field is required.", | |
minlength: "This field must contain at least 2 characters.", | |
email: "This is not a valid e-mail address." | |
}, | |
"account.password": { | |
required: "This field is required.", | |
minlength: "This field must contain at least 5 characters." | |
}, | |
security_password: { | |
required: "This field is required.", | |
minlength: "This field must contain at least 5 characters." | |
}, | |
security_username: { | |
required: "This field is required.", | |
minlength: "This field must contain at least 2 characters." | |
}, | |
firstname: { | |
required: "This field is required.", | |
minlength: "This field must contain at least 2 characters." | |
} | |
}, | |
highlight: function (element) { | |
$(element).closest('.form-group').removeClass( | |
'has-success').addClass('has-error') | |
}, | |
unhighlight: function (element) { | |
$(element).closest('.form-group').removeClass( | |
'has-error').addClass('has-success') | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment