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

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

        }
}









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
Regular expression
Regular expression  how i write a regular expression for a pattern which present in between
Advertisements
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
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
about regular expression - Java Beginners
about regular expression  Consider the grammar G: S -> ( L ) | a L -> L, S | S a) Eliminate the left-recursion from grammar G. b) Construct a recursive descent parser for G
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
A regular expression contains another regular expression - PHP
A regular expression contains another regular expression   Please explain how it works in PHP... RegEX1 = "a.*b"; RegEx2 = "a1.*b"; Thanks
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 contains character - PHP
Regular expression contains character  A PHP script that can check if the regular expression contains character
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
Regular expression in PHP for email - PHP
Regular expression in PHP for email  can any one tell me how to write regular expression in PHP for email to retrieve all the valid email ID's from the email
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
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
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
PHPMYSQL REGULAR EXPRESSION - WebSevices
PHPMYSQL REGULAR EXPRESSION  Hello all, I have to read a file and insert the match into mysql.File has a follwing lines. user196 Auth-Type := Local, User-Password == mypass@wd Session-Timeout = 3600
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
Regular Expression Search Program
Regular Expression Search Program       Regular Expression: Regular Expression is used to perform many... a matcher object which finds the character sequences for the regular expression
PHP Regular Expression
PHP regular expression allows programmer to perform various task like comparing, finding and replacing a particular type of strings. Using Regular... strings. PHP Regular expression also allows you to validate a email, phone
Reset the matcher using regular expression
Reset the matcher using regular expression  ... the String using regular expression. For this we are going to make program named Reset. java. The steps involved in program Reset. java are described below
Regarding regular expression with swing - Swing AWT
Regarding regular expression with swing  Regular Expression for value that should be greater than 0.0 and less than 999.9 0.0 > value < 999.9 Please Check it, in cell editor in JTable to validate a particular
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
Capturing Text in a Group in a Regular Expression
Capturing Text in a Group in a Regular Expression  ... the text in a group through the regular expression. Here, you can learn...; in the console output because the regular expression mentioned in the code detects
Parsing a String into Paragraphs Using a Regular Expression
Parsing a String into Paragraphs Using a Regular Expression       This section tells you how to parse the string into the paragraphs using regular expression in Java
Retrieving String by using Regular Expression
Retrieving String by using Regular Expression  ... the way to retrieve the String using Regular expression. For this we are going... and compiles the given regular expression into a pattern. Matcher m = p.matcher
Pattern resetting using regular expression
Pattern resetting using regular expression  ... the String using regular expression. For this we are going to make program named...):-Creating a pattern object and compiling the given regular expression
Getting the Indices of a Matching Group in a Regular Expression
the regular expression in Java. This section explains some method or APIs which... Getting the Indices of a Matching Group in a Regular Expression...;regular expression   Pattern pattern = Pattern.compile
Matching Zip code using regular expression
Matching Zip code using regular expression  ... code with the regular expression .For this we are going to make program named...;:-This is the regular expression use to match with Zip code.ADS_TO_REPLACE_1 matchZip("
Match string using regular expression without Case sensitivity
Match string using regular expression without Case sensitivity... the way to match the String using regular expression. For this we are going to make... JAVA have regular expressions Regular expressions are in Java
Pointing and indicating matcher using regular expression
Pointing and indicating matcher using regular expression... the given regular expression into a pattern. String matcher[]={" ^","  ... to point the matcher and also indicate the index of the matcher using regular
How can we extract string 'roseindia.net ' from a string http://deepak@roseindia. net using regular expression of php?
://deepak@roseindia. net using regular expression of php?   How can we extract string 'roseindia.net ' from a string http://deepak@roseindia. net using regular expression of php
Regular Expressions - Java Beginners
Regular Expressions  hi tried writing this program and got stuck give some help please Write a java program to accept name, phone number... expression = "^[\\w\\.-]+@([\\w\\-]+\\.)+[A-Z]{2,4}$"; CharSequence inputStr
Parsing Character-Separated Data with a Regular Expression
Parsing Character-Separated Data with a Regular Expression       This section illustrates you how... for separation the word of the sentences through the given regular expression
Finding word using regular expression
Finding word using regular expression   ... the given regular expression into a pattern. ADS_TO_REPLACE_1 String text... the String using expression. For this we are going to make program named
Finding start and end index of string using Regular expression
Finding start and end index of string using Regular expression... the way for finding start and end index of the string using regular expression...):-Creating a pattern object and compiling  the given regular expression
Split string after each character using regular expression
Split string after each character using regular expression... object and compiles the given regular expression into a pattern. Matcher m... to split the String after each character using expression. For this we are going
Appending and replacing string using regular expression
Appending and replacing string using regular expression... to append the String with the existing one using expression. For this we are going... = Pattern.compile("(Rose) (.net)"):-Creating a pattern object and compiling the given regular
Finding a given word using regular expression
Finding a given word using regular expression  ... and compiles the given regular expression into a pattern. Matcher matcher... a given word from the String and also the no of times the word exists using regular
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
Scheduler- cron expression - Java Beginners
cron expression functionality. My requirement is to run the cron expression every 20 minutes from the selected hour to hour.Ex: my cron expression is something... schueduer should fire every 20 minutes.But the cron expression behaviour
How to use regular expressions - Java Beginners
How to use regular expressions  how do i put a label and text field... in Java Swing to put label and text field on a frame. // LabelTextSwing.java... Friend, Here i am sending you full source code in Java Swing to put label
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

Ads