?
Solved

Validation in Javascript for Alphabets only

Posted on 2009-04-08
3
Medium Priority
?
7,940 Views
Last Modified: 2013-11-24
Validation in Javascript for Alphabets only
0
Comment
Question by:sandeepinat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Expert Comment

by:Sreedhar Vengala
ID: 24095181
function isValidAlpha()
{      
       var c=event.keyCode;      
       event.keyCode=(!( (c>=65 && c<=90)||(c>=97 && c<=122)|| (c==32)))?0:event.keyCode;
}
0
 
LVL 9

Accepted Solution

by:
Sreedhar Vengala earned 120 total points
ID: 24095188
also with regular expression:

regExpression = /^[A-Za-z]*$/ ;
            if(!regExpression.test(document.formname.TextBox1.value)){
                  alert(getMessage("Invalid Text"));
                  document.formname.TextBox1.focus();
                  document.formname.TextBox1.select();
                  return false;
            }
0
 

Expert Comment

by:designersx
ID: 24466163
this is what i ma doing but no alert is showing to me.
<script type="text/javascript">
regExpression = /^[A-Za-z]*$/ ;
function validate(){
	if(!regExpression.test(document.form.phone.value)){
                  alert(getMessage("Invalid Text"));
                  document.formname.TextBox1.focus();
                  document.formname.TextBox1.select();
                  return false;
            }
}
</script>
 
<form name="form" method="post" action="phone.php" onSubmit="return validate();">
Phone number: <input type="text" name="phone"><input type="button" value="submit"  />
</form>

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question