Reputation: 598
I found this regex in a plugin called hi5validator for jQuery, and I found it pretty good, I'm already using it on JavaScript:
/^([\+][0-9]{1,3}([ \.\-])?)?([\(][0-9]{1,6}[\)])?([0-9 \.\-]{1,32})(([A-Za-z \:]{1,11})?[0-9]{1,4}?)$/
I wanted to use this regex but in Java, and I tried to do this same thing with another regex in that library, but when I used an online evaluator, the expression gave lots of trouble. Fortunately, i found another regex that helped with that.
As for this one, can someone give me the proper Java version?
Upvotes: 0
Views: 71
Reputation: 726509
The logic of your regex is fine - you need to fix some minor details:
"
instead of slashes /
around your regex(
)
, dashes -
in trailing positions, pluses +
, colons :
, and dots .
inside character classes (I am not sure if it is necessary to escape these characters in Javascript either).Here is what you should get:
"^([+][0-9]{1,3}([ .-])?)?([(][0-9]{1,6}[)])?([0-9 .-]{1,32})(([A-Za-z :]{1,11})?[0-9]{1,4}?)$"
Upvotes: 3