Regex for matching multilingual numbers not detecting Chinese numbers

╄→гoц情女王★ 提交于 2021-02-07 13:34:37

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!