20712 downloads

how to use addRules() and Apply()

<scritp type="text/javascript" src="validate.js"></script>

<script type="text/javascript">
var myForm = new Validate();
myForm.addRules({id:'firstname',option:'required',error:'Le champ nom est obligatoire.'});
myForm.addRules({id:'email',option:'email',error:'Le champ email doit contenir une adresse mail valide.'});
</script>
<!--
if you use : myForm.Apply() errors will be returned to alert window
and if you use myForm.Apply('error_div') errors will be returned into DIV with id='error_div'
if your form is correct it will be submited to the specified url (<form...action="sendtopage"...>...</form>)
-->
<form id="form1" method="post" action="sendtopage" onsubmit="return myForm.Apply()">
first Name : <input name="firstname" type="text" id="firstname" /><br />
your E-mail : <input name="email" type="text" id="email" />
...
<input type="submit" name="Submit" value="Submit"/>
</form>
<scritp type="text/javascript" src="validate.js"></script>

<script type="text/javascript">

//call the javascript library "validate.js"

var f = new Validate();

</script>

Exemples


(Number)
email
Must contain http:// , https:// , ftp:// Or ftps://
xxx.xxx.xxx.xxx
0123456789abcdefghijklmnopqrstuvwxyz
chars caseSensitive
min : Max : 0 -> 10 (range)
NNN-NN-NNNN
positive or negative