Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Input field character sequence

Input Field to follow and check for the following algorithm. Maximum 11 alpha-numeric characters:

  1. 1st to 4th characters => Alphabetic characters- no numbers and special characters.

  2. 5th characters => 0 (Just a single Zero)

  3. 6th to 11th Characters => Alpha-numeric.

I think my question is quite simple, i want to enter 11 characters in an input field but first 4 characters should be as defined in point 1 and 5th character should be 0 and 6th characters to onward alphanumeric . input field should allow to enter characters as i defined , if some one want to enter 1 or other character at 5ht positions input field should not allow because 5ht position is for 0 and same expressions for other positions.

like image 627
Junaid Khan Avatar asked Jul 20 '26 22:07

Junaid Khan


1 Answers

Looks like you have to use regex:

$('input').val().match(/^[a-z]{4}0[a-z0-9]{6}$/i);
  1. ^ : Starts with
  2. [a-z] : Allows Alphabetic characters
  3. {4}: Matches 4 preceding characters
  4. 0 : Matches 0
  5. [a-z0-9]: Matches any characters from a-z and 0-9 in any sequence
  6. $: End of string
  7. i: Case insensitive match
like image 68
Tushar Avatar answered Jul 23 '26 13:07

Tushar