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();
                }
        }
}

Ads









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
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
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 '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 '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 '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 '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
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
pattern printing
pattern printing  
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 '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

Ads