views:

89

answers:

3

hi

i have a field called City , this should accepts only Characters but not special characters or numbers can any one help with regix logic

thanks in advance

thanks Sunny Mate

+2  A: 

Check out the Character API. Maybe you are looking for:

isLetter(..);

Or if this is used in a GUI then use a JFormattedTextField and you can specify an alphabetic mask.

camickr
+1  A: 

My hunch is your working on a JSF validation. I'd be surprised if this expression meets your final production ready needs, but here it goes:

[a-zA-Z]

A simple one page cheat sheet you might find useful

Brian
+1  A: 

The naive approach is to just find word letters, which is accomplished by [A-Za-z]+

But what about cities that have multiple words (New York City): ([A-Za-z]+\s?)+

But what about cities that have abbreviations or possessive words (St. Paul, Martha's Vineyard): ([A-Za-z\.\']+\s?)+

There are probably cleaner/more efficient ways to carry out the above, as I am not a regex master, but it's important to be mindful of some very likely alternatives to city names.

apiri
Just saw Mark Peters' comment on your question directly coincided with my answer. I'd have to agree with his thoughts.
apiri