I have an ISBN lookup. It has to be 10 characters. I have a custom validation rule to check that. But a lot of my customers are copying and pasting and when they do they tend to get an extra space at beginning or end. So I want to check for whitespace before or after the string and update it FIRST. And THEN run the regex. If it fails (not alpha numeric or more than 10 digits) then show error message.
Here's my current custom validation rule:
jQuery.validator.addMethod(
"isbn10rule",
function(value, element) {
var isValid = /^[a-zA-Z0-9]{10}$/.test(value);
return this.optional(element) || isValid;
},
"Must be exactly 10 characters and only letters and numbers"
);
I'm dont want answers that test against a scope restricted value. I need the value updated BEFORE the validation is even ran.
For example: String is " 0940087537"; If I try to paste that into the field, it immediately says "Must be exactly 10 characters and only letters and numbers". But if it stripped off that space first, then it would see there are only 10 characters left.