I need to have HTML's input elements pattern ignore the case of the value,
like have if the regex is /[a-z]*/ could I get it to match all uppercase letters too?
(I know I could just do /[a-zA-Z]*/, but that was an example.)
            Asked
            
        
        
            Active
            
        
            Viewed 1.5k times
        
    48
            
            
        
        Nick Beeuwsaert
        
- 1,598
 - 1
 - 11
 - 18
 
1 Answers
76
            I don't think it is possible.
The specification on
<input pattern>[1,2] specifies thatthe pattern uses the ECMAScript (i.e. Javascript) flavor of regex
it is compiled "with the global, ignoreCase, and multiline flags disabled"
In Javascript, the only way to make a regex ignore case is to set the modifier externally (
/.../i). The PCRE syntax(?i)is not supported.
Therefore, the pattern is always case-sensitive and [a-zA-Z]* (i.e. making the regex itself explicitly case insensitive) is the only way to match the pattern in a case-insensitive way.
        mikemaccana
        
- 110,530
 - 99
 - 389
 - 494
 
        kennytm
        
- 510,854
 - 105
 - 1,084
 - 1,005
 
- 
                    3@dominicbri7 "with [...] flags ***disabled***". If the flag to ignore case is disabled, then it doesn't ignore case, so it's case sensitive. – Niet the Dark Absol Jun 10 '14 at 15:37
 - 
                    Great answer. (The pedant on my shoulder would have preferred you to have written 'verbosely' or 'explicitly' instead of 'manually' but it doesn't stop your answer being helpful) – Martin Joiner Dec 10 '17 at 15:00
 - 
                    2so inconvenient when it comes to matching multiple terms in a case insensitive manner – oldboy Dec 26 '20 at 08:19
 - 
                    [sS][uU][cC][kK][sS]\. – King Friday May 03 '23 at 22:50
 - 
                    ...though I can't find where documentation claims they are disabled... – massic80 Jun 22 '23 at 08:23