JavaScript to validate input value is an Integer

May 3rd, 2006

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;

// }

// }

——————————————-

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.

Share

One Response to “JavaScript to validate input value is an Integer”

  1. Quyen Orlin says:

    Hello, I came across this blog article while searching for help with JavaScript. I have recently changed browsers from Opera to Microsoft Internet Explorer 5. After the change I seem to have a issue with loading JavaScript. Every time I go on a website that needs Javascript, the site freezes and I get a “runtime error javascript.JSException: Unknown name”. I cannot seem to find out how to fix it. Any help is greatly appreciated! Thanks

Leave a Reply

Before you post, please prove you are sentient.

what is 5 plus 6?