HTML5 Input Pattern Case-Insensitivity

前端 未结 2 466
独厮守ぢ
独厮守ぢ 2021-01-04 18:33

I\'m trying to create something right now and I need the pattern attribute that was introduced in html5 tp be case-insensitive but as far as I know, you can\'t

相关标签:
2条回答
  • 2021-01-04 18:50

    Ok I think I figured out an easier way to do the pattern other than listing each combination.

    As an example, I'll use the word, "five".

    [fF][iI][vV][eE]
    

    so

    pattern="[fF][iI][vV][eE]"
    
    0 讨论(0)
  • 2021-01-04 18:56

    You can use:

    pattern="[A-Za-z]{4}"
    

    For example:

    <input type="text" name="username" required pattern="[A-Za-z]{4}" />
    

    This input has to be filled up with four case-insensitive alpha characters.

    Update: You didn't respond which specific words you want to match but you can do it like:

    pattern="word|WORD|Word|wORD"
    

    So, for example:

    <input type="text" name="username" required pattern="word|WORD|Word|wORD" />
    

    Find more variations if needed.

    0 讨论(0)
提交回复
热议问题