0

https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_pattern

In the above code if we replace the pattern with pattern="(W-([0-9]{1,3})KG)?"

The values that should be expected is of the format: "W-23KG"

I know to ignore case sensitive, we have to use (?i)

So if the pattern is changed to pattern="(W-([0-9]{1,3})KG)?(?i)" below values are accepted: "w-23Kg" "W-23KG" "W-23kg"

But, what goes wrong is that it also accepts values like:

<!DOCTYPE html>
<html>
<body>

<form action="/action_page.php">
  Country code: <input type="text" name="country_code" pattern="(W-([0-9]{1,3})KG)?" title="Three letter country code">
  <input type="submit">
</form>

<p><strong>Note:</strong> The pattern attribute of the input tag is not supported in Internet Explorer 9 and earlier versions, or in Safari.</p>

</body>
</html>

"w-23kgW-23kgabcdefgh"

Sathya
  • 15
  • 4

1 Answers1

0

There is no universal way to ignore case in pattern attributes, but in your case, you can make the individual letters case insensitive with [Ww], [Kk], and so on.

<input type="text" name="country_code" 
       pattern="([wW]-([0-9]{1,3})[kK][gG])" 
       title="Three letter country code">
JLRishe
  • 99,490
  • 19
  • 131
  • 169