0

Now my app needs to check the input. I can recognize whether the input is Chinese, English or a number, but there are also special characters in Chinese and English. How to check this?

there is different between Special characters in Chinese mode and English mode,like this:</p>

chineseMode: , 。
EnglishMode:, .

Thanks for your answers.

4

2 回答 2

0

不确定它是否对您有帮助。您可以尝试使用正则表达式,也可以在此处添加其他特殊字符。

boolean result = yourString.contains("[-+.^:,]");
于 2013-03-28T07:13:11.220 回答
0

使用此方法检查特殊字符:

    Pattern p = Pattern.compile("[&%$#@!()*^]"); //<---- you can add more characters to check here 
    Matcher m = p.matcher(myEditText2);
    if (m.find()) {
        editText.setError("you can not enter special Character");
        return false;
    }

导入这些包:

import java.util.regex.Matcher;
import java.util.regex.Pattern;
于 2013-03-28T07:25:02.943 回答