Input field character sequence

Enter the input field and check the following algorithm. Maximum 11 alphanumeric characters:

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

  • 5 characters => 0 (just one zero)

  • 6th to 11th character => Alpha numeric.

I think my question is quite simple, I want to enter 11 characters in the input field, but the first 4 characters should be as defined in point 1, and the 5th character should be 0 and 6th characters for alphanumeric characters ... the input field should allow characters as defined by i, if someone wants to enter 1 or another character in the 5ht positions entry field, it should not be allowed as the 5ht position is for 0 and the same expressions for other positions.

+3


source to share


3 answers


It looks like you should be using regex

:

$('input').val().match(/^[a-z]{4}0[a-z0-9]{6}$/i);

      



  • ^

    : begin with
  • [a-z]

    : allows you to create alphabetic characters
  • {4}

    : matches the 4 preceding characters
  • 0

    : Compliant 0

  • [a-z0-9]

    : Matches any character from az and 0-9 in any order
  • $

    : End of line
  • i

    : Case insensitive
+1


source


You need to use regex for this.

/^[a-z]{4}0[\w]{6}$/

      



Demo: https://regex101.com/r/cK1sO4/1

0


source


To check the value in case of sensitivity, use this regular expression.

/ ^ [A-Za-Z] {4} 0 [\ w] {6} $ /

0


source







All Articles