Restrict Characters using regex matches in java

-1

Basically i have a java String which i want to restrict all the characters other than this regex code

String UcharSet = "^[a-zA-Z0-9-~!@#().]+";
if("hello.hi".matches(UcharSet)){
        UNotAllowedCharEC = "0x00000030";
}

now the problem is that my if statement always gets to execute although i have my regex to allow . so i really appreciate if somebody tell me what am i doing wrong.

java
regex
asked on Stack Overflow Sep 1, 2016 by jacky • edited Sep 1, 2016 by jacky

1 Answer

0

first i create a boolean which is equal to "hi+hello".matches(UcharSet) and i needed to create an if statement and see if it returned true or false:

boolean UMORN = "hi+hello".matches(UcharSet);
if(UMORN != true)
    UNotAllowedCharEC = "0x00000030";
answered on Stack Overflow Sep 2, 2016 by jacky • edited May 9, 2020 by Jean-François Fabre

User contributions licensed under CC BY-SA 3.0