I am using below code to validate fax number field in my qform
if(objFormEdit.postalCode.defaultValue.length <=5){
objFormEdit.postalCode.validateFormat('xxxxx','numeric', "Postal Code requires either a 5 or 9-digit number in either the format 'xxxxx' or 'xxxxx-xxxx'.");
}
else{
objFormEdit.postalCode.validateFormat('xxxxx-xxxx','numeric', "Postal Code requires either a 5 or 9-digit number in either the format 'xxxxx' or 'xxxxx-xxxx'.");
}
Its working fine but when i enter 1234-12345 then its change it to 12341-2345 and does not show any error. why its happening. I want error message in this case also.
Used custom function in qforms as below and it solved my problem.
function __isValidPostalCode()
{
var regx="^[0-9]{5}(?:-[0-9]{4})?$";
var regxObj = new RegExp(regx);
if( regxObj.test(this.value) == false )
{
this.error = "Postal Code requires either a 5 or 9-digit number in either the format 'xxxxx' or 'xxxxx-xxxx'.";
}
}
Load the function
_addValidator("isValidPostalCode", __isValidPostalCode);
called it as below
objFormEdit.postalCode.validateValidPostalCode();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.