user5740843 user5740843 - 18 days ago 7
HTML Question

Restricting form input goes haywire

I'm trying to restrict form input in a form that I have. The particular input is for an ID that has very specific requirements. An example of which would be:

YY.MM.DD-000.00

The code I'm working with to restrict it is:

<form>

<input type="text" class="form-control" id="nid"
name="nid" placeholder="@lang('app.nid')"
pattern="[00-99]{2}+\.[00-12]{2}\.[00-31]{2}+\-[000-999]{3}+\.[00-99]{2}"
title="YY.MM.DD-000.00"
value="" />
<button type="submit">
submit
</button>
</form>


And I can't seem to make it accept it. It seems refuses any input I give, both the bad and the supposibly good.

Can anyone help me figure out why?

Answer

It's because of those + in your regex. Not sure what you want there, but if you remove those it works. Those plus signs make your regex invalid.

Another problem was the - you escaped. This caused the regex not to work as well:

pattern="[00-99]{2}\.[00-12]{2}\.[00-31]{2}-[000-999]{3}\.[00-99]{2}"
Comments