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

RegEx of Pattern attribute #1

Closed
robsonsobral opened this issue Nov 9, 2018 · 7 comments
Closed

RegEx of Pattern attribute #1

robsonsobral opened this issue Nov 9, 2018 · 7 comments
Labels
bug Something isn't working

Comments

@robsonsobral
Copy link
Contributor

robsonsobral commented Nov 9, 2018

Hi!

Do you forgive me for not submit a test case? This is a matter of documentation.

The native validation of the pattern attribute modifies its value a little, before test it.

Shouldn't it be something like '^(?:' + field.getAttribute('pattern') + ')$' to respect the same rules?


I'm sorry for being the first annoying guy to open an issue.

@cferdinandi
Copy link
Owner

I'm so sorry, but it's no clear to me what you're trying to say. Have you tested it? The demo page uses on-page patterns and it works as-is.

@robsonsobral
Copy link
Contributor Author

I'm sorry, mister. My bad.

I think, despite you have give up on using the native API, the validation has to be the same.

From the specification:

[...] the regular expression language used for this attribute is the same as that used in JavaScript, except that the pattern attribute is matched against the entire value, not just any subset (somewhat as if it implied a ^(?: at the start of the pattern and a )$ at the end).

Which makes the ^ and $ on some demo samples unnecessary and allows some pattern mismatches. For example, your demo of the telephone number, matches 123-456-7890, but also 00000000000000123-456-7890, ABCD123-456-7890 or 123-456-7890-this RegEx's start isn't anchored to the start of the string neither its end is anchored to the end of the string.

There's still the case of the multiple attribute, which requires the RegEx to be tested on each value and the RegEx flag:

[..] compiled as a JavaScript regular expression with only the "u" flag specified [...]

I can submit a pull request, if you want to.

@cferdinandi
Copy link
Owner

Ah yes, I see what you mean. I... I suck at regex!

Yes, a pull request would be AWESOME, thank you!

@cferdinandi cferdinandi added the bug Something isn't working label Nov 10, 2018
@robsonsobral
Copy link
Contributor Author

@cferdinandi , may I add the lock and changelog files?

@cferdinandi
Copy link
Owner

No thanks. I use tags for changelog.

@robsonsobral
Copy link
Contributor Author

Wow, I wasn't talking about the release, but something to help others of analyze the changes in the future. It can be useful.


Pull request submitted!

@cferdinandi
Copy link
Owner

Fixed with v1.0.3. thanks for this, @robsonsobral !

cferdinandi added a commit that referenced this issue Dec 17, 2018
Not properly opening/closing custom regex patterns. See #20. Shoutout to #1 for the fix.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants