i'm using formvalidation plugin and i want to have two regex pattern. one to detect 6 characters with at least 1 digit and another one to detect spaces in password the user entered. the error message should be different for both of them this is one i need two patterns.
so far iv'e tried to use one javascript pattern
validators: {
regexp: {
regexp: /^[a-z\s]+$/i,
message: 'The full name can consist of alphabetical characters and spaces only'
}
}
and one inline pattern
<input type="text" class="form-control" name="fullName"
data-fv-regexp="true"
data-fv-regexp-regexp="^[a-z\s]+$
data-fv-regexp-message="The full name can consist of alphabetical characters and spaces only" />
when i have 1 javascript and 1 inline it will only use the inline.
and i also tried two javascript pattern but this is an error
validators: {
regexp: {
regexp: /^[a-z\s]+$/i,
message: 'The full name can consist of alphabetical characters and spaces only'
},
regexp: {
regexp: different regex,
message: 'different message'
}
}
does anyone knows how to do this?
The only way to use two regex on the same field is by using the
callback
validator.I suggest you to follow these steps:
First, check the length of your password, if it exceeds 6 characters long, exit with error (You don't need to use a regex to check for spaces if you do allow the use of them).
Second, count the number of used digits, if that number is < 1, exit with error (Here you can use a regex).
See the following code:
Live example:
References: