Regular Expression Not Working for at Least One European Character

Regular expression not working for at least one European character

You just need to remove the anchors and the quantifier and use test:

alert(/(?![×÷])[A-Za-zÀ-ÿ]/.test("ß1111"))
alert(/(?![×÷])[A-Za-zÀ-ÿ]/.test("ö"))
alert(/(?![×÷])[A-Za-zÀ-ÿ]/.test("12345"))

REGEX: How to allow exclusive latin characters (like accents)?

But I owe you an explanation as to why we have À-ÖØ-Ý and not just À-Ý

Foremost, this explanation what made exclusively for beginners:

When you use [A-Z], you capture any ASCII character between A and Z : you capture a range.

If you look at the Unicode U0000 character map/ASCII Table (see below), you'll notice that it matches exactly all uppercase.

Screenshot of an ASCII Table, Unicode U0000

In the same way, you can capture the 4 last lines of the Unicode U0080:
Screenshot of an ASCII Table, Unicode U0080

Though, you may realize that the multiplication (×) and division (÷) symbols are within that range.

Which is a problem because users (especially mobile users) could bypass the "only Latin letters" rule.

So to fix this issue we need to create 2 range of characters excluding these 2 characters.

Hence, why the À-ÖØ-Ýfor uppercase letters with accents and à-öø-ÿ for lowercase letters with accents.

I hope this will be useful to some people!

If you have any questions don't hesitate to ask them!

Sources:

https://fr.wikipedia.org/wiki/American_Standard_Code_for_Information_Interchange

https://fr.wikipedia.org/wiki/Table_des_caract%C3%A8res_Unicode/U0080

regex allows one character (it should not) why?

The "regular expression" you're using in your example script isn't a RegExp:

$(this).inputmask('Regex', { regex: "[\$]?([0-9,])*[\.][0-9]{2}" });

Rather, it's a String which contains a pattern which at some point is being converted into a true RegExp by your library using something along the lines of

var RE=!(value instanceof RegExp) ? new RegExp(value) : value;

Within Strings a backslash \ is used to represent special characters, like \n to represent a new-line. Adding a backslash to the beginning of a period, i.e. \., does nothing as there is no need to "escape" the period.

Thus, the RegExp being created from your String isn't seeing the backslash at all.

Instead of providing a String as your regular expression, use JavaScript's literal regular expression delimiters.

So rather than:

$(this).inputmask('Regex', { regex: "[\$]?([0-9,])*[\.][0-9]{2}" });

use

$(this).inputmask('Regex', { regex: /[\$]?([0-9,])*[\.][0-9]{2}/ });

And I believe your "regular expression" will perform as you expect.

(Note the use of forward slashes / to delimit your pattern, which JavaScript will use to provide a true RegExp.)

Regular Expression for at least one character and one number

Hey Try this expression

^\d*[a-zA-Z][a-zA-Z0-9]*$
  • Zero or more digits;
  • One alpha character;
  • Zero or more alphanumeric characters.

Try a few tests and you'll see this'll pass any alphanumeric string where at least one non-numeric character is required.

Concrete JavaScript regular expression for accented characters (diacritics)

The easier way to accept all accents is this:

[A-zÀ-ú] // accepts lowercase and uppercase characters
[A-zÀ-ÿ] // as above, but including letters with an umlaut (includes [ ] ^ \ × ÷)
[A-Za-zÀ-ÿ] // as above but not including [ ] ^ \
[A-Za-zÀ-ÖØ-öø-ÿ] // as above, but not including [ ] ^ \ × ÷

See Unicode Character Table for characters listed in numeric order.

Regex pattern including all special characters

Please don't do that... little Unicode BABY ANGELs like this one are dying! ◕◡◕ (← these are not images) (nor is the arrow!)

And you are killing 20 years of DOS :-) (the last smiley is called WHITE SMILING FACE... Now it's at 263A... But in ancient times it was ALT-1)

and his friend

BLACK SMILING FACE... Now it's at 263B... But in ancient times it was ALT-2

Try a negative match:

Pattern regex = Pattern.compile("[^A-Za-z0-9]");

(this will ok only A-Z "standard" letters and "standard" 0-9 digits.)

Regular Expression, RegEx, for validation of complex string in php

I hope this will do the trick :

^((([a-zA-Z])\\?)*(((0[0-2][0-9])|(03[0-2])|(035)|(092))\\?)*)+$

Successfully tested here.



Related Topics



Leave a reply



Submit