简体   繁体   中英

Java String Should Contain Only Letters and Dot

I would like to write a checker for my string input, I only wants my string to have capital letters and " . ".

I am thinking about writing code like a.match("^([A-Za-z]+$"); but I don't know how to exclude " . " from this statement. How can I do this?

[AZ.]+ should do the trick. Note, that you also don't want small letters.

^ and $ are not required because String.matches operates on the complete String.

The . requires no escape, because within character classes (the [...] part) a . has no special meaning.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM