Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-01-2013, 07:32 AM   PM User | #1
laddujadhav
New to the CF scene

 
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
laddujadhav is an unknown quantity at this point
Character validation

hello friends i want to validate only character validation for variable a & b in following code plz help.

function valid (){
a=document.form1.First.value
b=document.form1.Last.value
c=document.form1.Phone.value
d=document.form1.Suggestion.value
if(a=="")
{
alert("plz enter first name");
return false;
}
if(b=="")
{
alert("plz enter last name");
return false;
}
if(c=="")
{
alert("plz enter phone number");
return false;
}
if(isNaN(parseInt(c)))
{
alert("plz enter only number");
return false;
}
var x=document.forms["form1"]["E-mail"].value;
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
{
alert("Not a valid e-mail address");
return false;
}
if(d=="")
{
alert("plz enter some suggestion");
return false;
}
else
{
return true;
}
}
laddujadhav is offline   Reply With Quote
Old 02-01-2013, 07:36 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,103
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
I get a little weary of endlessly repeating this.

Form validation of the pattern if (document.formname.formfield.value == "") - that is blank - is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation. A proper name may only contain letters, hyphen, space and apostrophe.
Numeric values, such as zip codes, phone numbers and dates, should be validated as such. Ditto email addresses.

This topic has been covered many times before in this forum.
Most recently at http://www.codingforums.com/showthread.php?t=286820

alerts are nowadays regarded as obsolete and should only be used for debugging purposes. Use DOM methods to display a message to the user. It is better not to use text-speak.


All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 02-01-2013 at 07:56 AM..
Philip M is offline   Reply With Quote
Reply

Bookmarks

Tags
character validation, form validation, regex

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 Off

Forum Jump


All times are GMT +1. The time now is 01:07 AM.


Advertisement
Log in to turn off these ads.