0

Hello I have one input box here I enter 10 digit string so I want following validation on that entered string

  1. First 4 letter should be alphabet
  2. 5 to 9 letter should be numeric and
  3. Last 10 letter should be alphabet

Is there any validation process for this

For example

String should be ABBC12345A

It is valid string so how I add validation on input box in my angular

3
  • 1
    use a regex ... Commented Aug 8, 2017 at 8:10
  • @Pierre Emmanuel Lallemant You have any pattern Commented Aug 8, 2017 at 8:11
  • It should be like to this /^([a-zA-Z]){4}([0-9]){5}([a-zA-Z]){1}$/ Commented Aug 8, 2017 at 8:16

3 Answers 3

1

Try this

 /^([a-zA-Z]){4}([0-9]){5}([a-zA-Z]){1}$/
Sign up to request clarification or add additional context in comments.

Comments

1

As suggested in the comments, you can use regex. There are a few options, this is the way I like do do it.

/^(\w){4}(\d){5}(\w){1}$/
  • ^ start of string

  • \w matches any alpha character

  • \d matches any digit
  • {x} forces it to be x instances
  • $ end of string

Example: https://regex101.com/r/kPCRql/1

Comments

0

Please try the following:

<input [ngControl]="fullName" pattern="[a-zA-Z ]*">

And here is the documentation for your reference on regex https://www.w3schools.com/jsref/jsref_obj_regexp.asp

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.