• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Regular Expression in Javascript

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Friends!!
How do validate a word using regular expression in javascript, if i had to check that the word should have a only 1 alphabet and only 3 digits.
There should not be more more than one alphabet and 3 number and the first letter must be a letter.
eg.z999

Thanks
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah the fun world of reg exp
I am just learning this stuff....
see if this does the trick
<script>
function checkIt(Str) {
var StrRE = /^[a-zA-Z]\d\d\d/;
if (Str.match(StrRE)) {
return true;
}
else {
alert( "invalid!" );
return false; }
}
</script>
<input type="text" name="A" onchange="checkIt(this.value)">
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic