Skip to Main Content

Integration

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Regular expression to include whitespace character

km1612Aug 19 2015 — edited Aug 19 2015

Hi,

I am validating a phone number field and require the data in the field to start with + and contain numeric or whitespace characters.

Below is my code I am using to validate.

The value of b is always false.

Can you please let know the correct regular expression to use so that it returns true for a phone number with spaces ?

import java.util.regex.Pattern;

public class Hello {

    public static void main(String[] args) {

   

        String userContent = ("+0123 456 789");   

        boolean b = Pattern.matches("^\\+{1}?[0-9]\\s$", userContent);

        System.out.println("userContent :"+ userContent);

        System.out.println("b :"+ b);

    }

}

Thanks

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 16 2015
Added on Aug 19 2015
0 comments
431 views