Advertisement
Guest User

shit face

a guest
Sep 26th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. package assign2;
  2.  
  3. import java.util.*;
  4. import java.util.regex.Matcher;//to use matcher
  5. import java.util.regex.Pattern;//to use pattern
  6.  
  7. public class datecheck {
  8.  
  9. static Pattern pattern=null;//set both to null to begin
  10. static Matcher matcher=null;
  11.  
  12. public static void main (String [] args){
  13.  
  14. String inputString;
  15. Scanner mykeyboard = new Scanner(System.in);
  16. System.out.print("Type in Date to check if its valid: ");
  17. inputString = mykeyboard.nextLine();
  18.  
  19. //regular expression
  20. String patternvalidation="(([0-2][0-9]||[3][0-1])[/-]([0][1-9]||[1][0-2])[/-]([0][0-9]||[1][0-4]))";
  21.  
  22. pattern = Pattern.compile(patternvalidation);//reads through regular expression and compiles it
  23. matcher = pattern.matcher(inputString);//checks if input matches the regular expression
  24. if(matcher.matches())//if it does match print valid
  25. {
  26. System.out.println("Date is valid: " +inputString);
  27. }
  28. else//else not valid
  29. {
  30. System.out.println("ERROR: Date is not valid: " +inputString);
  31. }
  32.  
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement