Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validation

 
dale con
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all

I need to make sure a parameter going through to my method doesn not contains letters.

It's a phone number field so it can contain things like '-' or '+' or '()'etc but it can't contains letters

Can anyone help me write a regex for this

Many thanks
 
Junilu Lacar
Bartender
Posts: 7594
53
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you tried so far?

- Junilu
How to Ask Questions the Smart Way
 
Megs Maquito
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure if this is correct but here goes:


This way if anyone would use a String as parameter i.e. phoneNumber x = new phoneNumber (abc) would result in error as the method requires an integer and not a String.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic