yav - javascript validation tool
Home
Download
|
Support
Documentation
Getting started
Validation rules
Multi-language support
Learn by example
Simple registration form
Notification of changes
Newsletter Sign-up
Captcha
The andor-operator
Pre/Post/Implies rules
Working with the masks
Custom validation
Support
Discussion group
Mailing list
E-mail contact
Example 8
Here you can learn more about the custom validation.
Note that in the regular expressions you have to use '\\' instead of '\'.
(US telephone: matches +974-584-5656)
(IT telephone: matches 02-123456)
source
function checkUSTelephone() { var msg; var reg_1 = new RegExp("^[+][0-9]\\d{2}-\\d{3}-\\d{4}$"); if ( reg_1.test(document.forms['exampleform'].telephone_us.value) ) { msg = null; } else { msg = 'US telephone is invalid.'; } return msg; } function checkITTelephone() { var reg_2 = new RegExp("^([0-9]*\\-?\\ ?\\/?[0-9]*)$"); if ( reg_2.test(document.forms['exampleform'].telephone_it.value) ) { return null; } else { return 'Italian telephone is invalid.'; } } var rules=new Array(); rules[0]='telephone_us|custom|checkUSTelephone()'; rules[1]='telephone_it|custom|checkITTelephone()'; yav.addHelp('telephone_us', 'US telephone number with a compulsory prefix.'); yav.addHelp('telephone_it', 'Italian telephone number with optional prefix.');
Custom validation
US telephone:
IT telephone:
Copyright 2005-2008. All rights reserved.