简体   繁体   中英

Java Regex names (with spaces and special characters)

I am building a program for a French soccer federation.

The names should be able to consist of "letters, spaces, ', - , è and é".

But I am having trouble finding a good regex for this?

Well, if there is no other rules for names, this piece of code should work:

String name = "namé";
Pattern pattern = Pattern.compile("[A-Za-z'èé\\s\\-]*");
Matcher matcher = pattern.matcher(name);
System.out.println(matcher.matches());

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