Prepare for your Next Interview
|
Welcome to the Geeks Talk forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
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 three ...
|
|||||||
|
|||
|
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"); } }
|
|
|||
|
Re: JavaScript form address field validations
in onkeypress function you can check this one like this
function onlyno(){ key=key.event(); if(key.indexOf("0123456789")>-1){ return true else return false } } |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| IP address | timmy | PHP | 6 | 04-19-2009 02:43 AM |
| Validations on struts based applications | Lokesh M | Java | 2 | 11-19-2007 03:44 AM |
| website address validation needed | psuresh1982 | JavaScript | 1 | 08-13-2007 10:13 AM |
| JavaScript Tutorials | admin | JavaScript | 2 | 03-22-2007 08:17 PM |
| Field, single field and multivalue field | JobHelper | Seibel | 1 | 01-10-2007 12:54 PM |