-2

I have requirement to allow Special Characters and certain other characters for a field. I am using this regular expression:

"[a-zA-Z][a-zA-Z0-9._\\-]*[@][a-zA-Z0-9.\\-]+[.][a-zA-Z]+[a-zA-Z]"

So I need to add [at] instead of @ also add [.] insteat of . in my email validation

I try Like this

"[a-zA-Z][a-zA-Z0-9._\\-]*[\\[at]\\][a-zA-Z0-9.\\-]+[\\[dot]\\][a-zA-Z]+[a-zA-Z]"

But its Not Working and no idea to fix it.

Akoram M
  • 9
  • 1
  • Check if this will help you for email validation: https://stackoverflow.com/questions/46155/whats-the-best-way-to-validate-an-email-address-in-javascript – Avinash Apr 22 '22 at 06:55
  • This will really helpfull for me **UOY KNAHT** – Akoram M Apr 22 '22 at 07:12

1 Answers1

0

This worked for me:

"[a-zA-Z][a-zA-Z0-9._\\-]*\[at\][a-zA-Z0-9.\\-]+\[dot\][a-zA-Z]+[a-zA-Z]"
Edvin Pap
  • 90
  • 7
  • Would you please explain me the use of single \ backward slash in **RegEx**..? – Akoram M Apr 22 '22 at 07:09
  • Square brackets are used to define character class (matching one character in the set), if you want to use the square bracket character in the regex, you have to use a backslash before that. This is true for every special character. – Edvin Pap Apr 22 '22 at 07:13
  • For example while `a*` matching with 0 or more "a" characters, the `a\*` pattern matching on literally "a*". – Edvin Pap Apr 22 '22 at 07:17