Input pattern support

For technical support for all editions of CSS HTML Validator. Includes bug reports.
Post Reply
User avatar
RSteinwand
Rank VI - Professional
Rank VI - Professional
Posts: 550
Joined: Mon Jun 09, 2008 2:12 pm
Location: Fargo, ND
Contact:

Input pattern support

Post by RSteinwand » Mon Oct 31, 2016 9:32 am

Hi Albert,

I'm just playing with input patterns today.

Code: Select all

<input type=text pattern="\d*[.]?\d+" name=octpct>
I realize I could use type=number, but I'm not interested in the little number browser gadgets that have limited use. Who wants to click when it's easier to enter a number. Also iOS Safari doesn't support numbers.

CanIUse says no support for IE8 and Opera Mini. Limited support for Safari. http://caniuse.com/#search=pattern

Here's a good page for patterns: http://html5pattern.com and a good site for testing them: http://regexr.com

I noticed there was no warning or any info that leads me to believe pattern is checked and an empty field (pattern="") gives no error. Obviously checking for a valid pattern would be a lot of work.

Thanks.
Rick

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3221
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Input pattern support

Post by Albert Wiersch » Wed Nov 02, 2016 2:30 pm

Hi Rick,

The value of the "pattern" attribute is not checked. However, I've just now added a warning message for empty patterns for v17.

While I'm not going to write the code to fully check a pattern, I will see if there is a function somewhere that I can use and, if not, then I'll see if I can add some simple checking, like checking to make sure all the ()[]{} characters match.
Image
Albert Wiersch

User avatar
RSteinwand
Rank VI - Professional
Rank VI - Professional
Posts: 550
Joined: Mon Jun 09, 2008 2:12 pm
Location: Fargo, ND
Contact:

Re: Input pattern support

Post by RSteinwand » Wed Nov 02, 2016 2:37 pm

Hi Albert,

I would think the minimal check you described should be good enough.

Thanks.
Rick

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3221
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Input pattern support

Post by Albert Wiersch » Wed Nov 02, 2016 3:24 pm

Well good news.... :D

It looks like I was able to easily use a built-in component (TRegEx) to check the expression. The component uses PCRE (Perl Compatible Regular Expressions) though, but they are very similar to JavaScript regular expressions which is what the value of the "pattern" attribute is suppose to be.

UPDATE: Well bad news...... it doesn't seem to catch some things that I think it should.
Image
Albert Wiersch

User avatar
RSteinwand
Rank VI - Professional
Rank VI - Professional
Posts: 550
Joined: Mon Jun 09, 2008 2:12 pm
Location: Fargo, ND
Contact:

Re: Input pattern support

Post by RSteinwand » Wed Nov 02, 2016 4:29 pm

Nice try tho.
Rick

User avatar
Albert Wiersch
Site Admin
Site Admin
Posts: 3221
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX
Contact:

Re: Input pattern support

Post by Albert Wiersch » Wed Nov 02, 2016 4:44 pm

Well, good news now!

This seems to work well:
http://stackoverflow.com/questions/1723 ... expression

So I am also testing the regular expressions with this "regular expression" (some say that it's not technically a regular expression):
/^((?:(?:[^?+*{}()[\]\\|]+|\\.|\[(?:\^?\\.|\^[^\\]|[^\\^])(?:[^\]\\]+|\\.)*\]|\((?:\?[:=!]|\?<[=!]|\?>)?(?1)??\)|\(\?(?:R|[+-]?\d+)\))(?:(?:[?+*]|\{\d+(?:,\d*)?\})[?+]?)?|\|)*)$/
Boy does that look like gobbledygook! But it seems to work pretty well.
Image
Albert Wiersch

User avatar
RSteinwand
Rank VI - Professional
Rank VI - Professional
Posts: 550
Joined: Mon Jun 09, 2008 2:12 pm
Location: Fargo, ND
Contact:

Re: Input pattern support

Post by RSteinwand » Wed Nov 02, 2016 4:53 pm

LOL. Takes one to know one.
Rick

Post Reply