Check for Special Characters (/*-+_@&$#%) in a String

How to check for special characters using regex

There's a few things wrong with your expression. First you don't have the start string character ^ and end string character $ at the beginning and end of your expression meaning that it only has to find a match somewhere within your string.

Second, you're only looking for one character currently. To force a match of all the characters you'll need to use * Here's what it should be:

Regex objAlphaPattern = new Regex(@"^[a-zA-Z0-9_@.-]*$");
bool sts = objAlphaPattern.IsMatch(username);

Magento 2 : Allow special character at the end in password

You can special character which you want to add.

^[ A-Za-z0-9_@.#&+-]*$



Related Topics



Leave a reply



Submit