validation - Java - validating a subject Code -
i have subject code e.g: abc123 string
i need ensure of length 6, first 3 characters letters , last 3 numbers.
i try , in if
statement? can work length cannot figure out numeric , letter part of things. e.g:
public void isvalidcode(string subjectcode2){ str = subjectcode2; if (str.length() == 6 && """"need test others here??""" ) { system.out.println("the code valid"); } else { system.out.println("the code not valid"); }
you can use regular expressions, , matches()
method of string
class.
if (str.matches("[a-za-z]{3}[0-9]{3}")) { // validation succeeded } else { // validation failed }
Comments
Post a Comment