The pattern attribute in the <input> element is used to specify a regular expression that the input's value must match for it to be considered valid. The given pattern -?\d{1,3}\.\d+ matches strings that represent decimal numbers with an optional negative sign, typically used for latitude and longitude values.
Pattern Explanation:
-? allows for an optional negative sign.
\d{1,3} matches one to three digits.
\. matches a literal dot.
\d+ matches one or more digits.
Usage Example:
<input type="text" pattern="-?\d{1,3}\.\d+" placeholder="Enter latitude or longitude">
This pattern ensures the input matches the format of latitude/longitude values.
References:
MDN Web Docs on <input> pattern attribute
Regular Expressions Documentation
Contribute your Thoughts:
Chosen Answer:
This is a voting comment (?). You can switch to a simple comment. It is better to Upvote an existing comment if you don't have anything to add.
Submit