电话正则表达式[复制]

This question already has an answer here:

</head> 

<body> 

        <fieldset id="user-details">    

            <label for="name">Name:</label>
            <input type="text" name="name" value="" /> 

            <label for="email">Email:</label> 
            <input type="email" name="email" value=""  /> 

            <label for="phone">Phone: (Ex:(xxx)xxx-xxxx)</label>
            <input type="text" name="phone" value=""  />

            <label for="zipcode">Zip-Code</label>
            <input type="text" name="zipcode" value="" />

        </fieldset><!--end user-details-->

        <fieldset id="user-message">

            <label for="message">Message:</label> 
            <textarea name="message" rows="0" cols="0"></textarea> 

            <input type="submit" value="Enviar" name="submit" class="submit" />     

        </fieldset><!-- end user-message -->

    </form>

</body> 
</html>

Hi guys, so i need to divide phone into 3 squares, i think this is called regular expression and i really need help, for example (xxx) xxx xxxx , phone number should be like this!

I would appreciate you help thanks!!

</div>
\(\d{3}\)\s\d{3}\s\d{4}

This should work with this format (xxx) xxx xxxx. I didn't test it.

There is no standard regular expression for phone number. For your format regular expression is as follows:

       $PHONE_REGEX = /^([0-9]{3}) [0-9]{3} [0-9]{3}$/
       or
       $PHONE_REGEX = /^(\d{3})\s\d{3}\s\d{3}$/

In HTML5

     <input type='tel' name='phone' />  //This may not match the your pattern but easy to validate filed on client side

You do not need a regular expression for this. Just give the user 3 squares:

<label for="phone">Telefono: (Ej:(xxx)xxx-xxxx)</label>
(<input type="text" name="phoneareacode" value="" maxlength="3" />) <input type="text" name="phoneexchange" value="" maxlength="3" /> - <input type="text" name="phonenumber" value="" maxlength="4" />