-1

I need to make a validation for a student id input on my form how can I make it have a format like "A12345678" having a letter followed by 8 numbers

  • 2
    What have you tried? Have you made any attempt of solving this yourself? Please read: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) and also [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) – M. Eriksson Apr 21 '17 at 05:19
  • In this `A12345678` there are 8 numbers. – Sahil Gulati Apr 21 '17 at 05:19
  • try this `preg_match('/^A\d{7}$/','A1234567');` – Sahil Gulati Apr 21 '17 at 05:20

1 Answers1

-1

Add your validation in the input form like this

< input type='text' id="student_id" name="student_id" pattern="[A-Z,a-z]{1}[0-9]{8}" title="Enter Correct Student ID" class="form-control" required>

in pattern : [A-Z,a-z]{1} means 1 character is Alphabetic(upper or lower case)

[0-9]{8} means 8 characters are numeric

Hope it helps!!

  • This doesn't help with the back end validation, which the OP asked about. Even if you have this in the form, you should _always_ validate the data in the back end as well. _Never_ trust data that comes from users. – M. Eriksson Apr 21 '17 at 06:05
  • @MagnusEriksson maybe this can help
    :preg_match('/[a-z]\d{1,8}/','A12345678');
    – Ravi Kumar Apr 21 '17 at 06:16
  • Are you asking me to debug your answer for you? – M. Eriksson Apr 21 '17 at 06:19
  • Just trying to help. however just got some similar questions with answers : http://stackoverflow.com/questions/9296056/regex-for-2-letters-followed-by-4-digits AND http://stackoverflow.com/questions/17512890/php-preg-match-item-first-five-character-regex – Ravi Kumar Apr 21 '17 at 06:32
  • I know that you are, but you should (just like the OP should) test it yourself first. – M. Eriksson Apr 21 '17 at 06:38