开发者

how to check whether the given input field is String or not in java

i have a field called City , this should accepts only Characters but not special charac开发者_StackOverflowters 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜