not matching empty string for regex -
i trying use regex matching date(from 2000-2099). following regex okay.
((((^20[02468][048])|(^20[13579][26]))-(((0[13578]|1[02])-(0[1-9]|[12]\d|3[0-1]$))|((0[469]|11)-(0[1-9]|[12]\d|30$))|(02-(0[1-9]|1\d|2[0-9]$)))|((^20\d{2})-(((0[13578]|1[02])-(0[1-9]|[12]\d|3[01]$))|((0[469]|11)-(0[1-9]|[12]\d|30$))|(02-(0[1-9]|1\d|2[0-8]$)))))|0000-00-00){1}
note: match leap year(#days in month: 31, 30, 29
) or normal year(#days in month: 31, 30, 28
) or default(0000-00-00)
however matches empty string too. tried search solution this one mine way more complex , tried add {1,}
suggestion stated in link.
but doesn't work.
and don't understand why matches empty string well, please tell me too?
add required attribute input:
<input pattern="(((^20[02468][048])|(^20[13579][26]))-(((0[13578]|1[02])-(0[1-9]|[12]\d|3[0-1]$))|((0[469]|11)-(0[1-9]|[12]\d|30$))|(02-(0[1-9]|1\d|2[0-9]$)))|((^20\d{2})-(((0[13578]|1[02])-(0[1-9]|[12]\d|3[01]$))|((0[469]|11)-(0[1-9]|[12]\d|30$))|(02-(0[1-9]|1\d|2[0-8]$)))))|0000-00-00" type="text" required/>
the browser won't try validate empty input doesn't have required attribute.
http://jsfiddle.net/kyalhqpu/ vs http://jsfiddle.net/kyalhqpu/1/
Comments
Post a Comment