Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pattern match

Status
Not open for further replies.

edog1

Programmer
Oct 9, 2002
12
0
0
US
I have a jsp that validates a serial number, the first scenario is easy enough, starts with a "P" and is 10 characters long, if it doesn't pass that I need to see if it starts with an "O" then a letter and then 6 numbers.

ie: OE123456

what is the best way to perform this validation
 
If you're using J2SE 1.4 then you could use some regular expression method in the java.util.regex package ?
 
I saw that but Unfortunately I'm not able to use 1.4, any help ? thanks I'm new to java
 
Well i doubt this is the *best* way to do it but...

String s = new String("P123456789");
Integer myi;

if (s.startsWith("P") == true & s.length() == 10){

System.out.println("Starts with P and is 10 chars long");

try{

myi = new Integer(s.substring(1));
System.out.println("Valid - has 9 numbers");

}catch(Exception e){
System.out.println("Invalid - not got 9 numbers");
}


}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top