-1

I used a concept of taking a length of the input field and restrict the numbers and symbols as a first character but it doesn't work out. Can some one help me by using pipe concept to allow only a alphabet as a first character.

Thanks in advance

Naresh
  • 1
  • 1
  • 2
    Pipes are meant to transform the data from one form to another. If you want to restrict the user input you should go with directives! – Gangadhar Jannu Nov 09 '17 at 07:50
  • ya got it but i didn't get the perfect solutions.. Can you give a example code @GangadharJannu.. – Naresh Nov 10 '17 at 13:16

1 Answers1

1

You can use regular expression, like:

^[a-zA-Z][a-zA-Z0-9.,$;]+$?
Explanation:

^ Start of line/string.
[a-zA-Z] Character is in a-z or A-Z.
[a-zA-Z0-9.,$;] Alphanumeric or . or , or $ or ;.
+ One or more of the previous token (change to * for zero or more).
$ End of line/string.

The special characters I have chosen are just an example. Add your own special characters as appropriate for your needs. Note that a few characters need escaping inside a character class otherwise they have a special meaning in the regular expression.

I am assuming that by "alphabet" you mean A-Z. Note that in some other countries there are also other characters that are considered letters.

Aleks Andreev
  • 7,016
  • 8
  • 29
  • 37
Srijan
  • 43
  • 2
  • 7
  • I tried by using this regExp but not working. Can you give me a example code to integrate.. Note - First letter of input should be always alphabet even after user enter the value and click on home button, cursor moves to the first position then also only the alphabet should allow as a first character.. – Naresh Nov 10 '17 at 13:30