java regular expression

Ads
 

java regular expression

hi i need java expression which allows all characters with minimum 2 characters and maximum 20 characters in answers field after selecting security questions

View Answers

February 2, 2012 at 4:43 PM

import java.util.*;
import java.util.regex.*;

class RegularExpression {

        public static boolean validateString(String st) {
                return st.matches("^[a-zA-Z]{2,20}$");
        }

        public static void main(String[] args) {
                Scanner input = new Scanner(System.in);
                System.out.print("Enter String: ");
                String str = input.nextLine();
                while (validateString(str) != true) {
                        System.out.print("Invalid String!");
                        System.out.println();
                        System.out.print("Enter String: ");
                        str = input.nextLine();
                }

        }
}

February 2, 2012 at 4:43 PM

import java.util.*;
import java.util.regex.*;

class RegularExpression {

        public static boolean validateString(String st) {
                return st.matches("^[a-zA-Z]{2,20}$");
        }

        public static void main(String[] args) {
                Scanner input = new Scanner(System.in);
                System.out.print("Enter String: ");
                String str = input.nextLine();
                while (validateString(str) != true) {
                        System.out.print("Invalid String!");
                        System.out.println();
                        System.out.print("Enter String: ");
                        str = input.nextLine();
                }

        }
}

Ads









Related Tutorials/Questions & Answers:
java regular expression
java regular expression  hi i need java expression which allows all characters with minimum 2 characters and maximum 20 characters in answers field after selecting security questions
including index in java regular expression
including index in java regular expression  Hi, I am using java regular expression to merge using underscore consecutive capatalized words e.g.... from you is that is it possible using regular expression to avoid first word
Advertisements
Regular expression
Regular expression  how i write a regular expression for a pattern which present in between
Regular expression
Regular expression  I have the regular expression : var x=/(^\d+$)/ which allows only numbers. It does not accept character, decimals. However it accepts zero. I want an expression that takes numbers(no decimals)except zero
split string with regular expression
split string with regular expression  How to split string with regular expression in Java
Regular expression
Regular expression  can some one explain how below regex works, ndmurl1=${ndmurl#${ndmurl
Regular expression
Regular expression  how i extract string Coalition of civil society organizations and CSOs from string:- CSOs : What happening in Yemen is political crisis SANA'A, May 16 (Saba)- Coalition of civil society organizations (CSOs
javascript regular expression
javascript regular expression  i need a regular expression code for JavaScript
regular expression for special characters
regular expression for special characters  How to find out regular expression for special characters
regular expression for phone number
regular expression for phone number  Hi, i need the regular expression code for phone number in PHP. Thanks.   PHP - regular expression code for phone number \+?([0-9]{2})-?([0-9]{3})-?([0-9]{6,7
using regular expression
using regular expression  How can we extract string 'abc.com ' from a string http://[email protected] using regular expression of php
Regular expression in c++{MFC}
Regular expression in c++{MFC}  Hi ALL, I want to build a regular expression in c++{MFC} which validates the URL. The regular expression must... of %5C & %2F character. How can we develop a generic Regular Expression
Regular Expression for removing XML Tags
Regular Expression for removing XML Tags  Hi, Good Afternoon.I want a Regular expression in java which is removing the XML Tags in the specified... after applying regular expression is only "How are you".Need to remove all XML
Java validate phone number using regular expression
Java validate phone number using regular expression In this tutorial, you will learn how to validate the phone number using regular expression. The user is allowed to enter a number in a specific range i.e., a number should only
What is regular expression beginning of line ?
What is regular expression beginning of line ?  Hi, I one of my Java... and then replace the text using replaceAll() function of String. What is regular expression... this will be helpful for you. http://www.roseindia.net/java/string-examples/string
URL Regular Expression for Struts Validator
URL Regular Expression for Struts Validator  I want to know how to validate a url link in struts validation.xml. Please share me the regular expression for url link validation
URL Regular Expression for Struts Validator
URL Regular Expression for Struts Validator  I want to know how to validate a url link in struts validation.xml. Please share me the regular expression for url link validation
Regular Expression Help Help HELP!!!!
Regular Expression Help Help HELP!!!!  HI all I am very new to java, but i have this problem i got a string e.g Courses['07001'].Title... did that by using this expression String regex = "Courses\[\'[^\']+\'\]\.Title
PHP Regular Expression
PHP regular expression allows programmer to perform various task like... strings. PHP Regular expression also allows you to validate a email, phone... chunks. There are basically two types of PHP Regular Expression. POSIX
regular expression expalanation i need
regular expression expalanation i need  hi......... here is my code could explain it <html> <script language = "Javascript">... your regular expression. ^ shows beginning of string
Phone number validation using regular expression
Phone number validation using regular expression  Explain phone number validation using regular expression in JavaScript.   phone = phone.replace(/[^0-9]/g, ''); if(phone.length != 10) { alert("not 10 digits
match string to regular expression - Objective C
match string to regular expression - Objective C  How to match string value to regular expression in objective c?   Use NSPredicate. See the example given below... NSString *searchString = @"loginStatus"; NSString
Lambda Expression in Java 8
Lambda Expression in Java 8: Learn the power of Lambda Expression In this section we will learn about the Lambda Expression which is introduced in the Java... Expression in Java 8? The Lambda Expression is one of most important feature added
write a java program to solve the infix expression
write a java program to solve the infix expression  ==>> solve the below expression using java program: 2+5*2-5+6/2 using stack operations or any other process in java
how to execute a file in java at regular time intrevals automattically
how to execute a file in java at regular time intrevals automattically  how to execute a file in java at time retrievals automatically
Regarding Regular Expressions
Regarding Regular Expressions  Hi I would like to supply my regular expression with a 'default' value, so if the thing I was looking for is not found, it will return the default value as i have mentioned in the Regular
Regular expressions
Regular expressions  Sir/Madam, please tell me the meaning of the following code import java.io.*; import java.util.*; class Demo{ public static void main(String args[]){ double d=1000000.1232323d
Regularexpressions Tutorial
Regular Expressions Introduction In this tutorial I will show you how to use Regular Expressions in Java. What is Regular Expressions? A regular expression... expression Regular Expressions
expression and flow control
expression and flow control  write the program calculate and print... of services is regular (r) and premium (p) the rates are computed as follow - Regular services $ 10.00 plus first 50 minutes are free .Charges over 50 minutes
ModuleNotFoundError: No module named 'regular'
ModuleNotFoundError: No module named 'regular'  Hi, My Python... 'regular' How to remove the ModuleNotFoundError: No module named 'regular... to install padas library. You can install regular python with following command
Hibernate Expression
In this section we will discuss Hibernate Expression

Ads