Java regex validate number

Regular expression to accept only digits \d+$\d+$ This regular expression refers to a pattern which accepts only digits. Example package com.w3schools;   import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern;   public class RegexTest { private static final String PATTERN = "\d+$"; public static void main(String args[]){ List<String> values = new ArrayList<String>(); values.add("Jai"); values.add("12345345"); values.add("1234567890"); … Read more

Java regex validate 10 digit number

Regular expression to accept 10 digit number \d{10}\d{10} This regular expression refers to a pattern which accepts 10 digits number only. Example package com.w3schools;   import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern;   public class RegexTest { private static final String PATTERN = "\d{10}"; public static void main(String args[]){ List<String> values = new ArrayList<String>(); … Read more

java regex validate alphanumeric

Regular expression to accept alphanumeric only ^[a-zA-Z0-9]+$^[a-zA-Z0-9]+$ This regular expression refers to a pattern which accepts all lower and upper case characters, and digits only. Example package com.w3schools;   import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern;   public class RegexTest { private static final String PATTERN = "^[a-zA-Z0-9]+$"; public static void main(String args[]){ List<String> … Read more

Java regular expression metacharacters

Java regex metacharacters Regex Description . Any character (may or may not match terminator) d Any digits, short of [0-9] D Any non-digit, short for [^0-9] s Any whitespace character, short for [tnx0Bfr] S Any non-whitespace character, short for [^s] w Any word character, short for [a-zA-Z_0-9] W Any non-word character, short for [^w] b … Read more

Java Regex Quantifiers

Java Regex Quantifiers The quantifiers specify how often an element can occur. The symbols ?, *, + and {} define the quantity of the regular expressions.   Regex Description X? X occurs once or not at all X+ X occurs once or more times X* X occurs zero or more times X{n} X occurs n … Read more

Java regular expression character class regex

Java Regex Character classes Character Class Description [abc] a, b, or c (simple class) [^abc] Any character except a, b, or c (negation) [a-zA-Z] a through z or A through Z, inclusive (range) [a-d[m-p]] a through d, or m through p: [a-dm-p] (union) [a-z&&[def]] d, e, or f (intersection) [a-z&&[^bc]] a through z, except for … Read more

Java Regular expressions regex tutorial

Regular expressions Regular expressions represent a sequence of symbols and characters expressing a string or pattern to be searched for within a longer piece of text. The abbreviation for regular expression is regex. In programming regular expressions are mainly used to define constraints on strings like passwords, and email validation. The java.util.regex package primarily consists … Read more

java date time api

Java date time api provides the classes to represent and manipulate the dates. Classes to represent and manipulate dates are contained in java.time, java.util, java.sql and java.text packages. Java date time api tutorial: java util date class java.text.DateFormat class java text SimpleDateFormat class Java util calendar class Java util GregorianCalendar class java util timezone class … Read more

Java add days to current date

Java add days to current date example package com.w3schools;   import java.util.Calendar;   public class CalenderTest { public static void main(String args[]){ Calendar calendar = Calendar.getInstance(); System.out.println("The current date is : " + calendar.getTime()); calendar.add(Calendar.DATE, 10); System.out.println("10 days later: " + calendar.getTime()); calendar.add(Calendar.MONTH, 3); System.out.println("3 months later: " + calendar.getTime()); calendar.add(Calendar.YEAR, 4); System.out.println("4 years later: … Read more

Java convert date and time between timezone

Java convert date and time between timezone package com.w3schools;   import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone;   public class ConvertTimeZoneTest { private static final String DATE_FORMAT = "dd-M-yyyy hh:mm:ss a"; public static void main(String args[]) throws InterruptedException, ParseException{ SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT);   String dateInString = "09-04-2018 11:55:35 AM"; Date date = … Read more