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
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
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.
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
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.