简体   繁体   中英

how to use the pattern option to validate a phone number in grails <g:field type=text

I want users to just enter ten digits without punctuation. I have tried the patterns below. In each case a popup asks me to "Please match the requested format". I may switch to a jquery solution, but I am still curious why this isn't working?

Thanks for any insights, Sue

<label for="cellPhone">
            <g:message code="employees.cellPhone.label" default="Cell Phone" />
        </label>
        <g:field type="text" pattern="~/[0-9]{10}/" name="cellPhone1" placeholder="10-digit cell including area code" ></g:field>
        <g:field type="text" pattern="~[0-9]{10}" name="cellPhone2" placeholder="10-digit cell including area code" ></g:field>
        <g:field type="text" pattern="~/\\d{10}/" name="cellPhone3" placeholder="10-digit cell including area code" ></g:field>
        <g:field type="text" pattern="~\\d{10}" name="cellPhone4" placeholder="10-digit cell including area code" ></g:field>
        <g:field type="text" pattern="~/\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d/" name="cellPhone5" placeholder="10-digit cell including area code" ></g:field>
        <g:field type="text" pattern="~\\d\\d\\d\\d\\d\\d\\d\\d\\d\\d" name="cellPhone6" placeholder="10-digit cell including area code" ></g:field>

You don't need the ~/ as this is a client side thing

<g:field type="text"
         pattern="[0-9]{10}"
         name="cellPhone1"
         placeholder="10-digit cell including area code"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM