java - How to write the if condition for this situation? -


i need set error password field condition "only 2~22 characters , symbols , _ - allowed."

but little stuck here.

here got far:

if(   !(edittext.length() >= 2 && edittext.length() <= 22 ) ||     !(edittext.contains("-") || edittext.contains("_") || edittext.contains(","))   ) {   //set error message } 

but problem if input symbol other , _ or -, error message still doesn't show. input length, error message shows should though.

in java, use :

edittext.matches("^[a-za-z,_\\-]{2,22}$"); 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -