Prepare for your Next Interview
This is a discussion on JavaScript form address field validations within the JavaScript forums, part of the Web Development category; In javascript form validations, how to allow numbers, special characters, alphabets in address field? the address field doesn't allow only numbers or alphabets or characters. it allows all the ...
|
|||
|
JavaScript form address field validations
In javascript form validations, how to allow numbers, special characters, alphabets in address field? the address field doesn't allow only numbers or alphabets or characters. it allows all the three otherwise it shows the alert message.
if anybody konw the answer please explain me. |
| The Following User Says Thank You to ashaflint For This Useful Post: | ||
| Sponsored Links |
|
|||
|
Re: JavaScript form address field validations
Hi ashaflint,
Look at the following code.. function checkAddress(sText) { var ValidChars = "0123456789"; // Here what ever you want to put. As you mentioned numbers or alphabets or characters. var IsNumber=true; var Char; for (i = 0; i < sText.length && IsNumber == true; i++) { Char = sText.charAt(i); if (ValidChars.indexOf(Char) == -1) { IsNumber = false; } } return IsNumber; } In the above function sText is the value of the address field. I think it will help to you. ------------------------ suresh |
|
|||
|
Re: JavaScript form address field validations
Hi ashaflint,
I think it is easy to give the alert message when the user enters only numbers or alphabets or characters...Look at the following script, now i give the alert message when the user enters only numbers. function checkAddress(sText) { var ok = "0123456789"; var f=true; var Char; for (i = 0; i < sText.length && f == true; i++) { Char = sText.charAt(i); if (ok.indexOf(Char) == -1) { f = false; } } if (f==true) { alert("user enters only numbers"); } } So you can change this script to alphabets or characters also. The only thing is you should change the value of "ok". In the above function i give only numbers. I hope this will help to you. ----------------------- suresh |
|
|||
|
Re: JavaScript form address field validations
hi
the code given by suresh is correct but little modification then it will work function checkAddress(sText) { var ok = "0123456789"; var f=true; var Char; var text=sText.value; for (i = 0; i Char=text.charAt(i); if(ok.indexOf(Char) == -1) { f = false; } } if (f==false) { alert("user enters only numbers"); } } |
|
|||
|
Re: JavaScript form address field validations
sorry u copy this one
function checkAddress(sText) { var ok = "0123456789"; var f=true; var Char; var text=sText.value; for (i = 0; i Char=text.charAt(i); if(ok.indexOf(Char) == -1) { f = false; } } if (f==false) { alert("user enters only numbers"); } } |
|
|||
|
Re: JavaScript form address field validations
function checkAddress(sText)
{ var ok = "0123456789"; var f=true; var Char; var text=sText.value; for (i = 0;i Char=text.charAt(i); if(ok.indexOf(Char) == -1) { f = false; } } if (f==false) { alert("user enters only numbers"); } } |
|
|||
|
Re: JavaScript form address field validations
function checkAddress(sText)
{ var ok = "0123456789"; var f=true; var Char; for (var i = 0;i Char=sText.charAt(i); if(ok.indexOf(Char) == -1) { f = false; } } if (f==false) { alert("user enters only numbers"); } } ![]() |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| IP address | timmy | PHP | 4 | 3 Weeks Ago 07:06 AM |
| Validations on struts based applications | Lokesh M | Java | 2 | 11-19-2007 02:44 AM |
| website address validation needed | psuresh1982 | JavaScript | 1 | 08-13-2007 09:13 AM |
| JavaScript Tutorials | admin | JavaScript | 2 | 03-22-2007 07:17 PM |
| Field, single field and multivalue field | JobHelper | Seibel | 1 | 01-10-2007 11:54 AM |