Solved

Validation in Javascript for Alphabets only

Posted on 2009-04-08
3
7,936 Views
Last Modified: 2013-11-24
Validation in Javascript for Alphabets only
0
Comment
Question by:sandeepinat
  • 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 30 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn how to implement Singleton Design Pattern in Java.
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…

839 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