Geeks Talk

Prepare for your Next Interview




JavaScript form address field validations

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


Go Back   Geeks Talk > Web Development > JavaScript

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 04-05-2007
Junior Member
 
Join Date: Mar 2007
Location: Hyderabad
Posts: 2
Thanks: 0
Thanked 2 Times in 2 Posts
ashaflint is on a distinguished road
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.
Reply With Quote
The Following User Says Thank You to ashaflint For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 05-10-2007
Contributing Member
 
Join Date: Sep 2006
Location: bangalore, india
Posts: 1,007
Thanks: 0
Thanked 73 Times in 62 Posts
psuresh1982 will become famous soon enough
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
Reply With Quote
  #3 (permalink)  
Old 05-14-2007
Contributing Member
 
Join Date: Sep 2006
Location: bangalore, india
Posts: 1,007
Thanks: 0
Thanked 73 Times in 62 Posts
psuresh1982 will become famous soon enough
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
Reply With Quote
  #4 (permalink)  
Old 05-17-2007
Contributing Member
 
Join Date: May 2007
Location: Chennai
Posts: 34
Thanks: 0
Thanked 5 Times in 4 Posts
samineni6 is on a distinguished road
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");
}
}
Reply With Quote
  #5 (permalink)  
Old 05-17-2007
Contributing Member
 
Join Date: May 2007
Location: Chennai
Posts: 34
Thanks: 0
Thanked 5 Times in 4 Posts
samineni6 is on a distinguished road
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");
}
}
Reply With Quote
  #6 (permalink)  
Old 05-17-2007
Contributing Member
 
Join Date: May 2007
Location: Chennai
Posts: 34
Thanks: 0
Thanked 5 Times in 4 Posts
samineni6 is on a distinguished road
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");
}
}
Reply With Quote
  #7 (permalink)  
Old 05-17-2007
Contributing Member
 
Join Date: May 2007
Location: Chennai
Posts: 34
Thanks: 0
Thanked 5 Times in 4 Posts
samineni6 is on a distinguished road
Re: JavaScript form address field validations

getting problem while displaying for loop

for (i = 0;i
Reply With Quote
  #8 (permalink)  
Old 10-25-2007
Banned
 
Join Date: Oct 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
sarithahere528 is on a distinguished road
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");
}
}
Reply With Quote
Reply

  Geeks Talk > Web Development > JavaScript


Thread Tools
Display Modes


Similar Threads

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


All times are GMT -4. The time now is 05:49 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved