• 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

Regex validation

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a String of between 1 and 5 chars in length. It must contain at least one alphabetic character (i.e. a-zA-Z). The rest can be numeric or spaces. Is is possible to validate this using regex?

For example:

1aa is valid
123 is not valid


I tried using:
^[a-zA-Z]{1,5}$
but it doesn't work if there are any numerics in the string.
I also tried
^[a-zA-Z]{1,}$ and some other variations.

Can anybody give me any pointers as to where I'm going wrong?

Thanks,

John
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those regular expressions don't include digits or spaces.
[ April 12, 2007: Message edited by: Keith Lynn ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic