0

I use a regex in a model and I use the Judge gem to perform the client side validation, because the judge based its client side validation on the models, it uses the user email regex in both Ruby and javascript.

The problem is that the regex is not javascript compatible, I guess. So I need to find a regex that is compatible with both Ruby and Javascript, for email validation. (But also for mobile, etc...)

Is there any tool, website or whatever to help me change all my regex?

/\A\s*(([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})[\s\/,;]*)+\Z/i

1 Answer 1

3

Your issue here is that javascript doesn't now the \A\Z anchors.

If you're not using the m flag (multiline), you can replace then with ^$:

/^\s*(([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})[\s\/,;]*)+$/i

For reference, ^$ are anchors matching the beginning and end of the string, except if you use the m flag: then they match the beginning and end of a line.

\A\Z always match beginning and end of the string.

Sign up to request clarification or add additional context in comments.

2 Comments

Does they mean start and end?
@Vadorequest: Answer edited, you can also look here for more info if you like: regular-expressions.info/anchors.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.