Question

I am working on a grails applications and want the ability to do validation on a g:textField. I just want to make sure that numbers are numbers and words are words. I would like to avoid doing it through JS but if that is the only way, then so be it. Here is what I am trying out.

<g:textField type="number" pattern="^(?:[-+]?[1-9]\d*|0)?(?:\.\d+)?\$" class="form-control" name="hours" value="${hours}"/></div>

Any suggestions or directions? Or should I just do it through JS?

Was it helpful?

Solution

So I was able to figure out the correct regex. The issue that I was having was about the escape characters and the way they were being interoperated.

<g:textField type="number" pattern="^[0-9]+\\s*\$|^[0-9]+\\.?[0-9]+\\s*\$" required="true" class="form-control" name="hours" value="${deliverable.estimatedHours}"/>

This will now check the format for an input string and make sure that it only contains numbers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top