Pruthviraj Mohite
Pruthviraj Mohite

Reputation: 91

Regular Expression for Alphanumeric characters with one special char in between

can anyone please help me to figure Regex attribute for string field. I want my string should be in format of FirstName@LastName thats is it.. I require only one special char in between and rest all alphabets only..

Upvotes: 2

Views: 73

Answers (2)

Sufiyan Ghori
Sufiyan Ghori

Reputation: 18763

If you want to accept any non-alphanumeric characters in the middle, like $,@,_,- etc, you can use the following,

[a-zA-Z]+[^a-zA-Z\d\s][a-zA-Z]+

it will match all these among others,

FirstName@LastName
FirstName-LastName
FirstName_LastName
FirstName$LastName
FirstName:LastName

Live Demo

If you want to match whitespace in between as well then simply remove \s from above expression.

Hope it helps.

Upvotes: 1

Codor
Codor

Reputation: 17605

You can use the expression [A-Za-z]+@[A-Za-z]+ to test against a nonempty string of alphabetical characters, followed by an @ sign and again followed by a nonempty string of alphabetical characters. You can test it online here.

Upvotes: 3

Related Questions