Domanda

1). I am using the following regex for validating email address:

"^(?=.*\\d)(?=.*[A-Za-z])[A-Za-z0-9@~!%^*_#$-=.+,]{7,50}$"

The problem is that it works fine when the above regex is used.
But when i change the order of characters in here in the part :

[A-Za-z0-9@~!%^*_#$-=.+,] to [A-Za-z0-9@~*_-=.+!%^#$],

ie., place the characters '!%^#$' after +,

It gives an exception :

[4/8/14 11:58:09:315 IST] 000000b4 SystemErr     R java.util.regex.PatternSyntaxException: Illegal character range near index 38
^(?=.*\d)(?=.*[A-Za-z])[A-Za-z0-9@~*_-=.+!%^#$]{7,50}$

How does ordering of characters matter in regex?

2). Also i am using LDAP for registering and storing email addresses & passwords.

For that also when I give '!#$%'*-=?^_@testnone.com' as an input for registration : it is throwing an "javax.naming.NameAlreadyBoundException" but when i change the order of characters in the email to '!#$%'*?=^_-@testnone.com' it is able to register.

Basically, what I found was that when I place '-' at last(before @) in email it works fine, but when I put it before any other character it throws exception.

How does ordering matter in LDAP?
È stato utile?

Soluzione

If you put - inside the [] it needs to be first so it won't be seen as a range separator. In your first example you are effectively allowing [$-=]; in the second it becomes [_-=], which is rejected as _ is after = lexically.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top