Input pattern validation - More than one pattern

I've been using the input type inside a form in HTML and using the pattern attribute in order to better validate the data entry.

Is there a way to permit more than one pattern in a single input type?

For instance, I'd like to permit both [a-zA-Z]{1}\d{8} and d{8}\[a-zA-Z]{1}

This would be one of the inputs I've used so far but as you can see I have there just one pattern:

<input type="text" id="txtID" pattern="[a-zA-Z]{1}\d{8}" required/>

It might be possible that since my knowledge of RegEx is limited there might be a way to use a RegEx formula that permits boths patterns but I really don't know.

Answers


You can use alternation operator | to allow alternative patterns:

[a-zA-Z]\d{8}|d{8}[a-zA-Z]

Note that you do not need to add any anchors or grouping, see pattern documentation:

This implies that 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).


Need Your Help

Which alternative to choose for a database redesign (sports stats, competitions, geographic scopes)?

mysql database-design tree parent-child entity-relationship

I'm extending a database, which is about sports stats. The different leagues, or more precisely "competitions", can be represented by a tree structure analogous to certain geographic areas (scope/r...

Publishing SWF that uses Flex SDK

actionscript-3 flash-cs4

When i test the flash application from inside the flash-cs4 it works fine, but when i try to export the movie, it gives an error:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.