3

There is this snippet from the HTML specification, but either I do not understand the specification or it does not exactly say anything too informative regarding the regex-modifiers.

1
  • What are you trying to achieve? Commented Sep 23, 2015 at 14:29

1 Answer 1

5

You should check this HTML5 pattern attribute documentation:

If an input element has a pattern attribute specified, and the attribute's value, when compiled as a JavaScript regular expression with the global, ignoreCase, and multiline flags disabled (see ECMA262 Edition 5, sections 15.10.7.2 through 15.10.7.4), compiles successfully, then the resulting regular expression is the element's compiled pattern regular expression. If the element has no such attribute, or if the value doesn't compile successfully, then the element has no compiled pattern regular expression. [ECMA262]

So, there is no way to apply regex modifiers to this attribute.

Just in case you need to use case-insensitive patterns: use character classes, e.g. to match "ball", use pattern="[Bb][Aa][Ll]{2}".

Multiline mode is usually just not necessary as in the majority of cases, a single line string is being checked.

As the regex is anchored by default, there is no point to support g modifier.

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

1 Comment

If you have any further doubts, please drop a comment. Note that in angularjs, you pass either a string or a regex with usual JS delimiters. Perhaps, you will like the idea to use ng-pattern.

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.