By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,282 Members | 1,569 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,282 IT Pros & Developers. It's quick & easy.

Java script validation for numeric and text field

P: 1
Hi.,

Please help me for java script validation for text and numeric field.
May 23 '07 #1
Share this Question
Share on Google+
4 Replies


DeMan
100+
P: 1,806
Hi Thiyagusathya ,
Welcome to the scripts. I am moving your post to the JavaScript forum where you will get a better response from javascript experts. In future you can find this by selecting the forums option on the blu bar at the top of the screen.
I hope you find the answers you require
May 23 '07 #2

acoder
Expert Mod 15k+
P: 16,027
Hi.,

Please help me for java script validation for text and numeric field.
Have a look at the validation links in the Offsite Links thread (sticky).
May 23 '07 #3

P: 5
Hi.,

Please help me for java script validation for text and numeric field.

HI
you can use the following function for the fields you want to validate

Number Validation:

Expand|Select|Wrap|Line Numbers
  1. function numericValidate(string) {
  2.     var intCharCode;
  3.     for (var i = 0; i < string.length; i++) {
  4.       intCharCode = string.charCodeAt(i);        
  5.         if (!((intCharCode >= 48 && intCharCode <= 57))) 
  6.         return false; (or)
  7.                     alert("it is not a number");
  8.     }
  9. }

String Validation:(it wont allow spaces between or at any place in the string)

Expand|Select|Wrap|Line Numbers
  1. function strValidate(string)
  2. {
  3.     var testName =/^([a-z]|[A-Z]| )*$/;
  4.     if(!testName.test(string))
  5.     {
  6.         return false; (or) alert("Enter only string values");
  7.     }
  8. }
May 25 '07 #4

P: 1
@Thiyagusathya
Basicallly When we trying to validate a form some time we need numeric validation for textbox.

We can validate textbox by onkeypress event of the control By checking whether the keycode of the key pressed as the user types falls within the range of the number keys 48-57(i.e 0-9 and '.') ,if not belong to that range it will return false then it will disable the keypress action
Jun 16 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.