Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change \A and \z to ^ and $ in regex #36

Closed
wants to merge 1 commit into from

Conversation

jokklan
Copy link
Contributor

@jokklan jokklan commented Oct 1, 2014

Hey

I tried to add a email validator to my application, based on the rails guides on validations, like this:

validates :email, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i }

The problem is that javascript doesn't seem to support \A (start of string) and \z (end of string), but only ^ (start of line) and $ (end of line). However i can't use that in my validation, because rails will throw a error telling me to use the multiline options, which is not really what i want.

I made this small fix, that replaces \A with ^ and \z with $. This would properly be temporary if you still plan on implementing a XRegExp plugin, but it was the one most important difference between regex in ruby and javascript I could find :)

@Dinuz
Copy link

Dinuz commented Nov 24, 2014

@joecorcoran this solves the regex issue in ruby. The solution works perfectly. I suggest to merge it.

Best
Dinuz

@dhumphreys
Copy link

👍 on this. I am a new user and had to immediately make this fix yesterday for one of our applications. This is essential in Rails 4 since ^ and $ cause security problems and are flagged by Rails.

@saurabhbhatia
Copy link
Collaborator

Works nicely for me too actually. I tested it with Rails 4.2.1 👍

@saurabhbhatia
Copy link
Collaborator

I will find some time tomorrow and write a spec for this.

@jamesmk
Copy link
Collaborator

jamesmk commented May 16, 2015

@saurabhbhatia #14 and #34 both solve the regex issue too, but I'm leaning towards this one because the others have diverged more. A test here would be great!

@jamesmk
Copy link
Collaborator

jamesmk commented May 25, 2015

Thanks @jokklan! I pulled your commit into #60 and added test cases to it. Will merge as soon as Travis is green.

@jamesmk jamesmk closed this May 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants