Web Simplified….
3 May
JavaScript Validation: Script to validate input value is an Integer.
We will use Regular Expression and exec() function to do the validation.
Sample Code:
//Code for Form which captures click event and calls ‘validate()’ function.
//function validate()
// {
//frm = document.form
//var freg = /(^\d\d*$)/;
// var Intval = frm.text.value;
//if(!fr.exec(Intval))
// {
// alert(”Only Integer Value allowed”);
// return false;
// }
// }
//function validate()
// {
//frm = document.form
//var freg = /(^\d\d*$)/;
// var Intval = frm.text.value;
//if(!fr.exec(Intval))
// {
// alert(”Only Integer Value allowed”);
// return false;
// }
// }
//
——————————————-
Code Explanation:
Create a Regular Expression variable
var freg = /(^\d\d*$)/;
Use exec function to see if it matches regular expression – if it return ‘False’ show the message and return false.
if(!fr.exec(Intval))
That’s it. Hope this help you guys:-)
Advertisement: Varshyl Tech offers website designing, logo designing, Search engine promotion, custom software development solutions.
Leave a reply