When the apostrophe is not an apostrophe - .Net / Javascript check

I have a regular expression checker for emails in .NET 2.0 that uses client-side validation (javascript).

Current expression: "\ w + ([- +. '] \ W +) @ \ w + ([-.] \ W +). \ W + ([-.] \ W +)", which works for my needs (or so I thought).

However, I had a problem with apostrophes, as I had a copy / paste of the email address from Outlook in the form text field

Chris.OBrian@somerandomdomain.com

You can see that the apostrophe is another character from what happens if I just typed a text box

'vs - but both are apostrophes

Ok, I thought, just add this character to the check string to get

"\ W + ([-. + '] \ W +) @ \ W + ([-.] \ W +) \ W + ([-.] \ W +)."

I will copy the β€œspecial” apostrophe into the validation expression, then I type in the email address and use the same clipboard element to paste the apostrophe, but the validation is still pending.

The apostrophe is not like the .net code behind the file in the form of a .net form, and since verification is not yet done, I assume that it is considered a different character due to some kind of .cs encoding of the source file?

Is this plausible, has someone else encountered the same problem?

thanks

+4
source share
4 answers

You must add '+' after ([- +. ''] \ W +) to allow multiple groups of "words". The expression you express allows only two words, and you have three: Chris, Oh, Brian.

Hope this makes things easier.

+1
source

In something like Outlook, there will be a tendency to use Smart Quotes.

Here is some background information

+1
source

If you simply pasted ' (U+2019 RIGHT SINGLE QUOTATION MARK) into your document and this did not work, it means that your document is not using Unicode.

When you encode and send a file as UTF-8 (for example), it works fine without further changes. Otherwise, you need to avoid this through \u2019 , which also works in JavaScript regular expressions:

 "\w+([-+.'\u2019]\w+)@\w+([-.]\w+).\w+([-.]\w+)" 
+1
source

In XML, you can check the value of an apostrophe character by evaluating it by reference to its character:

 ' 

However, this entity does not exist in the SGML HTML form. And as an added bonus, JavaScript cannot compare a single quote with a double quote. By comparison, they were rated as true. The only solution is to convert the single quote and double quote characters to a reference to the symbol object of your invention, perform a comparison, and then replace these invented object references with the corresponding quote symbols.

0
source

All Articles