问题
I'm trying to use patterns for my gsp file in Grails. I want to check if the time entered is in the correct format. For example: 12.15 == 12:15 == 12,15 == 12-15 and so on.
<g:field type="text" name="startTime" class="date" pattern="\\$##:##"/>
<g:field type="text" name="endTime" class="date" pattern="[0-9]{2}:[0-9]{2}" />
That's my code. The patterns are just some trys. Maybe someone knows a solution.
Greetings Nik
回答1:
the pattern
in your g:field tag will be pass into date template (for example: /_fields/date/_field.gsp) like you pass parameters into other templates. You can access it by ${pattern}
.
You can use any validator such as bootstrap_validator
or jquery_inputmask
to do the task
回答2:
I found a solution:
<g:textField name="startTime" class="date"
value="${formatDate(format:'HH:mm',date:record.start)}" pattern="\\d{1,2}(:\\d{0,2})?" />
<g:textField name="endTime" class="date"
value="${formatDate(format:'HH:mm',date:record.end)}" pattern="\\d{1,2}(:\\d{0,2})?"/>
I just skiped the part with different dots. Now it shows a warning if you use the wrong pattern.
来源:https://stackoverflow.com/questions/25525375/grails-field-pattern-for-different-time-formats