Solved

Validation in Javascript for Alphabets only

Posted on 2009-04-08
3
7,931 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now