Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine if a string is alphabetic 1

Status
Not open for further replies.

mooster2

Programmer
Jan 26, 2004
21
CA
In my HTML page, I have a Javascript portion that tells the user to enter his nickname because he has been accepted for a high score (it's a game :) ). I used the prompt command as follows:

tempname = prompt("You finished with a score of " + score + ".\nPlease enter your nickname for the Hall of Fame.", "Anonymous")

Now I only want the user to enter letters (no numbers, spaces or symbols)

Is there a function like: tempname.isAlpha() to see if the
users has entered only letters? If not, what can I do to verify that the string stored in "tempname" is composed of letters only?

is it something like if ( tempname > 'a' && tempname < 'z') ??
 
include this on your page:
Code:
<script type="text/javascript">
String.prototype.isAlpha = function() {
  return /^[a-z]+$/i.test(this);
}
</script>

then you can call it using:
if( tempname.isAlpha() ) {
// do something
}

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top