问题
I have a method which detects whether a String is a number:
public static boolean isNumber(String num)
{
return num.matches("(\\p{N})+");
}
The above method is successfully matching English, Hindi, Arabic numbers but fails to match Chinese numbers:
三十萬零二百五十 etc.
Is it possible to create a regex which can match a number from any language(or major languages)?
edit: the number won't be a decimal, it will be used to validate a phone number.
回答1:
as some have already pointed out in the comments, these are the words used for numbers, i.e. "one", "two", "three" etc.
China introduced the indo-arabic numbers in the 19th century, so \p{N} should also match Chinese numbers. If you also want the literals, you should include them, as stribizhev suggested.
来源:https://stackoverflow.com/questions/32523130/regex-for-matching-multilingual-numbers-not-detecting-chinese-numbers