0

How to validate the car registration number in android.I am giving like this every time it shows toast message.I want like this AP05TB3456.can any one solve this isssue?

String numPlate = "(([A-Za-z]){2,3}(|-)(?:[0-9]){1,2}(|-)(?:[A-Za-z]) {2}(|-)([0-9]){1,4})|(([A-Za-z]){2,3}";

if (reg_no.getText().toString().equalsIgnoreCase("")||!reg_no.getText().toString().contentEquals(numPlate))
           {
               Toast.makeText(MoreInfoactvity.this, "Please Enter Valid Registration Number", Toast.LENGTH_SHORT).show();
           }
Anilkumar
  • 47
  • 1
  • 8

1 Answers1

0

Try with this below regex.

(([A-Za-z]){2,3}(|-)(?:[0-9]){1,2}(|-)(?:[A-Za-z]){2}(|-)([0-9]){1,4})|(([A-Za-z]){2,3}(|-)([0-9]){1,4})4

Exmple :

GJ 05 AB 8460
Harshad Pansuriya
  • 20,189
  • 8
  • 67
  • 95
  • its not working for me will u comment total syntax please – Anilkumar Sep 04 '16 at 08:27
  • !reg.getText().toString.equals((([A-Za-z]){2,3}(|-)(?:[0-9]){1,2}(|-)(?:[A-Za-z]){2}(|-)([0-9]){1,4})|(([A-Za-z]){2,3}(|-)([0-9]){1,4})4) this iis right syntax or not? – Anilkumar Sep 04 '16 at 08:33
  • @Anilkumar No you have to Implement pattern and then Match with your text. see here is good Explanation : http://stackoverflow.com/questions/10327901/how-to-use-regular-expression-in-android – Harshad Pansuriya Sep 04 '16 at 08:36