pattern matcher

pattern matcher

i want a number in a specific range in pattern matcher..for example a number should only be in the range of 6-9 digits...if it exceeds or decrease it should show an error.Here is the code which i am trying...i this it checks for 10 digits...but i want it in the range of 6-9

import java.util.regex.Matcher; import java.util.regex.Pattern;

public class ValidatePhoneNumber { public static void main(String[] argv) {

  String sPhoneNumber = tf.getText();


  Pattern pattern = Pattern.compile("\\d{10}");
  Matcher matcher = pattern.matcher(sPhoneNumber);

  if (matcher.matches()) {
      System.out.println("Phone Number Valid");
  }
  else
  {
      System.out.println("Phone Number not valid");
  }

} }

View Answers

November 23, 2012 at 10:57 PM

import java.io.*;

import java.util.regex.*;

class pmatch

{

public static void main(String args[])throws IOException
    {

Pattern p=Pattern.compile("[0-9]{9}|[0-9]{8}|[0-9]{7}|[0-9]{6}");

System.out.println("Enter no.");

BufferedReader br=new BufferedReader (newInputStreamReader(System.in));

    String exp=br.readLine();
    Matcher m=p.matcher(exp);
   boolean b=m.matches();
    if(b==true)
    System.out.println("Valid number");
    else
    System.out.println("Invalid number");
    }
}

November 24, 2012 at 12:12 PM

Here is a code that validates phone number.

import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ValidatePhoneNumber {
  public static boolean validatePhone(String phone) {
                return phone.matches("^[0-9]{6,9}$");
        }
    public static void main(String[] argv) {
      Scanner input = new Scanner(System.in);
      System.out.print("Enter Phone Number: ");
                String phone = input.nextLine();
                while (validatePhone(phone) != true) {
                        System.out.print("Invalid PhoneNumber!");
                        System.out.println();
                        System.out.print("Enter Phone Number: ");
                        phone = input.nextLine();
                }
        }
}









Related Tutorials/Questions & Answers:
pattern matcher
= tf.getText(); Pattern pattern = Pattern.compile("\\d{10}"); Matcher matcher...pattern matcher  i want a number in a specific range in pattern matcher..for example a number should only be in the range of 6-9 digits
pattern
of different sizes. The size of each pattern is determined by the number of columns or rows. For example, a pattern of size 5 has 5 columns and 5 rows. Each pattern is made of character $ and a digit, which shows the size. The size must
Advertisements
Pattern
Pattern  How to print this pattern in Java please help me A AC ACE ACEG ACEGI The program should be right to left
pattern
pattern  1 3 1 5 3 1 7 5 3 1 9 7 5 3   Here is a number pattern example. 1 3 1 5 3 1 7 5 3 1 9 7 5 3 1 class Pattern{ public static void main(String args[]){ for(int i=1;i<=9;i
Pattern
Pattern  1234321 123 321 12 21 1 1 please,give me this pattern in java   class Sixth_1 { public static void main(String args...; } } }   Here is a number pattern class Pattern{ public
Pointing last index of the Matcher
Pointing last index of the Matcher       This Example describes the way to point the matcher and also indicate the last index of the matcher using expression.For this we
ModuleNotFoundError: No module named 'matcher'
ModuleNotFoundError: No module named 'matcher'  Hi, My Python... 'matcher' How to remove the ModuleNotFoundError: No module named 'matcher... to install padas library. You can install matcher python with following command
Pointing and indicating matcher using regular expression
the given regular expression into a pattern. String matcher[]={" ^","  ... a matcher for matching the given input against pattern p.ADS_TO_REPLACE_2 m.find... Pointing and indicating matcher using regular expression
Pattern matching
Pattern fnamepat = Pattern.compile("fname=\"([^<>]+)\" "); Matcher fmatch...Pattern matching  String tagvalue = I've above string and I need... or any string handling concept. I'm trying Pattern fnamepat = Pattern.compile
ModuleNotFoundError: No module named 'color-matcher'
ModuleNotFoundError: No module named 'color-matcher'  Hi, My... 'color-matcher' How to remove the ModuleNotFoundError: No module named 'color-matcher' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'company-matcher'
ModuleNotFoundError: No module named 'company-matcher'  Hi, My... named 'company-matcher' How to remove the ModuleNotFoundError: No module named 'company-matcher' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'company-matcher'
ModuleNotFoundError: No module named 'company-matcher'  Hi, My... named 'company-matcher' How to remove the ModuleNotFoundError: No module named 'company-matcher' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'invenio-matcher'
ModuleNotFoundError: No module named 'invenio-matcher'  Hi, My... named 'invenio-matcher' How to remove the ModuleNotFoundError: No module named 'invenio-matcher' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'name-matcher'
ModuleNotFoundError: No module named 'name-matcher'  Hi, My Python... 'name-matcher' How to remove the ModuleNotFoundError: No module named 'name-matcher' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'pytest-matcher'
ModuleNotFoundError: No module named 'pytest-matcher'  Hi, My... named 'pytest-matcher' How to remove the ModuleNotFoundError: No module named 'pytest-matcher' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'taxonomy-matcher'
ModuleNotFoundError: No module named 'taxonomy-matcher'  Hi, My... named 'taxonomy-matcher' How to remove the ModuleNotFoundError: No module named 'taxonomy-matcher' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'text-matcher'
ModuleNotFoundError: No module named 'text-matcher'  Hi, My Python... 'text-matcher' How to remove the ModuleNotFoundError: No module named 'text-matcher' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'text-matcher'
ModuleNotFoundError: No module named 'text-matcher'  Hi, My Python... 'text-matcher' How to remove the ModuleNotFoundError: No module named 'text-matcher' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'tfidf-matcher'
ModuleNotFoundError: No module named 'tfidf-matcher'  Hi, My... 'tfidf-matcher' How to remove the ModuleNotFoundError: No module named 'tfidf-matcher' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'color-matcher'
ModuleNotFoundError: No module named 'color-matcher'  Hi, My... 'color-matcher' How to remove the ModuleNotFoundError: No module named 'color-matcher' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'colour-matcher'
ModuleNotFoundError: No module named 'colour-matcher'  Hi, My... named 'colour-matcher' How to remove the ModuleNotFoundError: No module named 'colour-matcher' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'company-matcher'
ModuleNotFoundError: No module named 'company-matcher'  Hi, My... named 'company-matcher' How to remove the ModuleNotFoundError: No module named 'company-matcher' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'Django-Matcher'
ModuleNotFoundError: No module named 'Django-Matcher'  Hi, My... named 'Django-Matcher' How to remove the ModuleNotFoundError: No module named 'Django-Matcher' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'fuzzy-matcher'
ModuleNotFoundError: No module named 'fuzzy-matcher'  Hi, My... 'fuzzy-matcher' How to remove the ModuleNotFoundError: No module named 'fuzzy-matcher' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'genice_matcher'
ModuleNotFoundError: No module named 'genice_matcher'  Hi, My... named 'genice_matcher' How to remove the ModuleNotFoundError: No module named 'genice_matcher' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'inspire-matcher'
ModuleNotFoundError: No module named 'inspire-matcher'  Hi, My... named 'inspire-matcher' How to remove the ModuleNotFoundError: No module named 'inspire-matcher' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'invenio-matcher'
ModuleNotFoundError: No module named 'invenio-matcher'  Hi, My... named 'invenio-matcher' How to remove the ModuleNotFoundError: No module named 'invenio-matcher' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'json-matcher'
ModuleNotFoundError: No module named 'json-matcher'  Hi, My Python... 'json-matcher' How to remove the ModuleNotFoundError: No module named 'json-matcher' error? Thanks   Hi, In your python
pattern printing
pattern printing  
Pattern Matching
Pattern Matching  hello, What operator performs pattern matching?   hii,ADS_TO_REPLACE_1 The "LIKE" operator performs the pattern matching in SQL
Design pattern
Design pattern  explain factory pattern
Pattern Making
Pattern Making  how to print this pattern in java? * * * * * * * * * * * * * * * * * It is just an example
Version of com.arusarka>json-hamcrest-matcher dependency
List of Version of com.arusarka>json-hamcrest-matcher dependency
ModuleNotFoundError: No module named 'json-schema-matcher'
ModuleNotFoundError: No module named 'json-schema-matcher'  Hi, My... named 'json-schema-matcher' How to remove the ModuleNotFoundError: No module named 'json-schema-matcher' error? Thanks   Hi
ModuleNotFoundError: No module named 'matcher-pcx-synomia'
ModuleNotFoundError: No module named 'matcher-pcx-synomia'  Hi, My... named 'matcher-pcx-synomia' How to remove the ModuleNotFoundError: No module named 'matcher-pcx-synomia' error? Thanks   Hi
ModuleNotFoundError: No module named 'speed-friending-matcher'
ModuleNotFoundError: No module named 'speed-friending-matcher'  Hi...: No module named 'speed-friending-matcher' How to remove the ModuleNotFoundError: No module named 'speed-friending-matcher' error? Thanks   
ModuleNotFoundError: No module named 'string_set_matcher'
ModuleNotFoundError: No module named 'string_set_matcher'  Hi, My... named 'string_set_matcher' How to remove the ModuleNotFoundError: No module named 'string_set_matcher' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'fuzzy-sequence-matcher'
ModuleNotFoundError: No module named 'fuzzy-sequence-matcher'  Hi...: No module named 'fuzzy-sequence-matcher' How to remove the ModuleNotFoundError: No module named 'fuzzy-sequence-matcher' error? Thanks   Hi
ModuleNotFoundError: No module named 'Github-Contributor-Matcher'
ModuleNotFoundError: No module named 'Github-Contributor-Matcher'  Hi...: No module named 'Github-Contributor-Matcher' How to remove the ModuleNotFoundError: No module named 'Github-Contributor-Matcher' error? Thanks
ModuleNotFoundError: No module named 'gtfs-map-matcher'
ModuleNotFoundError: No module named 'gtfs-map-matcher'  Hi, My... named 'gtfs-map-matcher' How to remove the ModuleNotFoundError: No module named 'gtfs-map-matcher' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'json-schema-matcher'
ModuleNotFoundError: No module named 'json-schema-matcher'  Hi, My... named 'json-schema-matcher' How to remove the ModuleNotFoundError: No module named 'json-schema-matcher' error? Thanks   Hi
pattern program
pattern program  can some one plz help me to wright the logic for the following pattern abcdcba abc cba ab ba a a ab ba abc cba abcdcba
Java pattern
Java pattern  Write a Java program that outputs the following pattern. 1 21 321 4321 54321 654321
pattern program
pattern program  can any 1 print the following pattern in java .plz give the code.and yes thank u so much for answering my 2 other questions.had i... before.anyways the pattern goes like this abcdcba abc cba ab ba a a ab ba abc abc
pattern program
pattern program  13579 1357 135 13 1 pattern program in java   Here is your Example:- package Compare; public class PatternDemo { public static void main(String [] args){ int c=10; for(int i=0;i<
Code for Pattern
Code for Pattern   1 23 345 5678 891011 Please write the code of above program and please do not use in this string tokennizer, string buffer etc i mean to say that please use very simple method
Coder for Pattern
Coder for Pattern  1 12 123 1234 12345 please write the program of above pattern and do not use string tokennizer string buffer i mean to say that please use very simple method Thanks   public class PatternExample
pattern
pattern generation
pattern generation  write a program to print pattern shown below 1 2 3 4 5 16 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9   Here is an example of number spiral. public class NumberSpiral{ public
Maven Dependency json-hamcrest-matcher >> 1.0
You should include the dependency code given in this page to add Maven Dependency of com.arusarka >> json-hamcrest-matcher version1.0 in your project

Ads