Expand my Community achievements bar.

Validating Complicated Required Field

Avatar

Former Community Member
I am trying to come up with the correct validation scipt for a field that requires 13 characters - either numbers or numbers and x's, but does not allow for dashes, other letters or other characters. It is used for ISBN, and needs to be regulated because the professors cannot seem to grasp what is required. Can anyone help?
2 Replies

Avatar

Level 6
Here you go. Put this in the validate event for your field. It will strip out any characters other than 0123456789xX and then check that the result has 13 characters.



validateISBN(this.rawValue);



function validateISBN(s) {

var rExp = /[^0123456789xX]/gi;

var strFilteredString = s.replace(rExp, "");

this.rawValue = strFilteredString;

return (strFilteredString.length == 13)

}



Jared Langdon

www.jlangdon.ca

Avatar

Former Community Member
Thank you. This worked great for what I need. Your help is much appreciated.