File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Validator RegExp for Telephone

 
Wagner Danda Da Silva Filho
Ranch Hand
Posts: 80
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I need a help to create a regular expression to validate telephone field with Struts Validator. The regexp should be very simple: 4 numeric digits, a "-" char, and again more 4 numeric digits. Ex: "3131-3131".

Any ideias?
 
Wagner Danda Da Silva Filho
Ranch Hand
Posts: 80
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found this solution:

\d{4,4}-\d{4,4}

In struts validation.xml:

<field property="phone" depends="required,mask">
<arg0 key="client.phone"/>
<var><var-name>mask</var-name>
<var-value>^\d{4,4}-\d{4,4}$</var-value></var>
</field>



Wagner Danda
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic