Negate characters for Regex email
source link: https://www.codesd.com/item/negate-characters-for-regex-email.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Negate characters for Regex email
I am trying to write a basic regex to validate an email address. For this specific case I am trying to make sure the string inputted only includes letters, numbers, "." and "@". Or in other words I am making sure it doesnt include characters like £&¬! etc.
I tried getting the NOT version of this [[:alnum:].@]+ so that it would highlight a character not in that set but I couldnt get it to work. I also tried characters not in [\W.@]+ (the . is meant to be escaped but stackoverflow is removing the \ from this post) but the \W is still picking up the . and @ symbols.
You can ...
- ... match for positives (your regex plus anchors to make sure it matches the complete test string)
(^[[:alnum:].@]+$
) - ... match for negatives which means that at some point an illegal character occurs
([^[:alnum:].@]
)
... and check whether there has been a match. n the first case that means 'ok', in the second 'fail'.
Theer are regex dialects that do not support posix character classes, in this case replace [:alnum:]
with 0-9a-zA-Z
.
Related Articles
Using regex for simple email validation
Replacing multiple characters in an email column in Oracle
PHP regex email still allowing 2 points one after the other
How to parse a line for an email address in perl using a regular expression?
Wmic command how to use the negative number for the search
How to disinfect a string for regex
Define the value of the column according to the regex email address?
Best practices for validating email addresses (including + in gmail addresses)
Exception handling for the Email command
Delete invalid characters from the email
Check if the string is a subset of a group of characters? (RegEx)?
what is the best way to check the cc cc field for incorrect email addresses in java
Delete all exclusive Latin characters using regex
Incorporating characters for Europe and America
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK