Posts

Showing posts from March, 2017

Mobile Validation Using Java Regular Expression

Image
We discussed here to validate Indian mobile number using concept of regular expression and Indian mobile numbering convention follows a particular protocol 1.India mobile number contains 10 digits 2.First digit of any number is either 7,8,9 and rest 9 lies between 0-9 3.if we include country code then number will be either 11 or 12 digits  a) In case of 11 digits First digit will be 0  b) In case of 12 digits First two digits will be 91 So at first we design regular expression which follows above rules At first we write a rule which follow first number will be either 7,8 or 9 and for this we will write [7,8,9] or in short we can write like this [7-9] after that we have to write rest 9 digits between 0-9 and for this in case of regular expression we can write like this [0-9][0-9].........[0-9] either [0-9] 9 times or in short [0-9]{9} And when we want to write std code then in case of 11 digit i.e to write 0 and in case of 12 digits we write std code as 91 and to full

Java Regular Expression

Image
Java Regex or Regular Expression is an API to define Pattern for searching or manipulating Strings, In simple word we can say that Regular expression is a representation of a group of String object according to a particular Pattern. Java provides the java.util.regex package for pattern matching with regular expressions. java.util.regex package consists of following three classes : Pattern Class In Pattern class Pattern object is a compiled version of a regular expression. It contains a compile() method which is used to create a Pattern. Pattern class provides no Public constructors.              Public static Pattern compile(String) Matcher Class Matcher object match the given pattern in the  target String Matcher object is created by matcher() method of Pattern Class     Public Matcher matcher (String target) Important Methods of Matcher class S. No. Method Description 1 boolean find() Returns boolean value after mat