• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need help in regular expression

 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want my script to validate for age field. I want age field to accept only 2 numeric digits.However , i always get false as my output. Please explain me how can i do this?

NOTE iam giving 2 digits in the age field...like 22,32, etc but still the output is "false"



[ September 24, 2008: Message edited by: Maan Shenoy ]

[ September 24, 2008: Message edited by: Maan Shenoy ]
[ September 24, 2008: Message edited by: Maan Shenoy ]
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You code is saying to look at the letter d two times. You are missing the \

Eric
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

var patt= /^d{2}$/;



i have changed above to

var patt= /^\d{2}$/;

However , above is not working either...
please tell me wht is to be done now?
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks guys...

got the answer, i had put patt in double quotes.....

i.e
i had it this way

var patt1 = new RegExp("patt");

i removed the above double quotes and now it works fine...

thanks
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I missed that you used new RegExp

When you use this syntax: var patt= /^\d{2}$/; it already is a regular expression, so you do not have to use RegExp with it.

Eric
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic