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:

chineseMode: , 。
EnglishMode:, .

Thanks for your answers.

Xoangle
  • 405
  • 6
  • 11

2 Answers2

0

Not sure if it will help you.you can try like this using regex and also you can add other special characters here.

boolean result = yourString.contains("[-+.^:,]");
Android Killer
  • 18,174
  • 13
  • 67
  • 90
0

Use this method to check special characters:

    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 these packages:

import java.util.regex.Matcher;
import java.util.regex.Pattern;
Shiv
  • 4,569
  • 4
  • 25
  • 39