For creating email addresses is allowed to insert only these characters, please help me to create regex that allows only these characters.
http://www.novell.com/documentation/groupwise2014r2/gwsdk_admin_rest_api/data/b12nem8w.html
Invalid Characters in Internet Email Addresses
Internet email addresses must include only RFC-compliant characters, which include:
- Numbers 0-9
- Uppercase letters A-Z
- Lowercase letters a-z
- Plus sign +
- Hyphen –
- Underscore _
- Tilde ~
This is my regex, I don’t understand why this {} characters not remove
var input = "?}{)(&^%#@*/.09Aa+7-8_8~_8*!";
Regex r = new Regex("(?:[^a-z0-9-+'-'-_-~])", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
var dd = r.Replace(input, "_");
Console.WriteLine(dd);
Console.Read();
>Solution :
Look at your pattern:
a-z0-9-+'-'-_-~
Breaking that down, you allow:
atoz0to9-,+'to'– a single character_to~– a range of 32 characters, which includes both{and}
Fix your regex pattern to only include the valid characters, and your code will work:
Regex r = new Regex("(?:[^a-z0-9\\-+'_~])", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
Output:
_____________09_a+7-8_8~_8__
.NET Regular Expressions | Microsoft Docs
