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;


// {

// 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.

That’s it. Hope this help you guys :-)

Advertisement: Varshyl Tech offers website designing, logo designing, Search engine promotion, custom software development solutions.