Posted By

pablazo on 05/15/07


Tagged

java String validation


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

olivernautsch
bsteadman
rtipton
vkolev


String Validation


 / Published in: Java
 

URL: http://www.thescripts.com/forum/thread17738.html

  1. String x = "LLL 00 LLL";
  2.  
  3. if ( x.length()==9
  4. && java.lang.Character.isLetter(x.charAt(0))
  5. && java.lang.Character.isLetter(x.charAt(1))
  6. && java.lang.Character.isLetter(x.charAt(2))
  7. && java.lang.Character.isSpace (x.charAt(3))
  8. && java.lang.Character.isDigit (x.charAt(4))
  9. && java.lang.Character.isDigit (x.charAt(5))
  10. && java.lang.Character.isSpace (x.charAt(6))
  11. && java.lang.Character.isLetter(x.charAt(7))
  12. && java.lang.Character.isLetter(x.charAt(8))
  13. && java.lang.Character.isLetter(x.charAt(9)))
  14. {
  15. // do something for match
  16. }
  17. else {
  18. // do something for not match
  19. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: fuzzylollipop on November 13, 2009

this would be much much simpler with a regular expression.

You need to login to post a comment.