Geeks Talk

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.

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

Go Back   Geeks Talk > Web Development > JavaScript
Register Blogs FAQ Tag Cloud 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,016
Thanks: 0
Thanked 91 Times in 72 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,016
Thanks: 0
Thanked 91 Times in 72 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
  #9 (permalink)  
Old 04-25-2009
Junior Member
 
Join Date: Apr 2009
Location: chennai
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
nagasen is on a distinguished road
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
}

}
Reply With Quote
Reply

  Geeks Talk > Web Development > JavaScript

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are Off


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


All times are GMT -4. The time now is 12:01 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved