A Tip A Day #7 – US Phone Validation Using RegEx

This post is a part of the daily blog series  A Tip A Day, daily dosage of learning!  Day #7 - US Phone Validation Using RegEx (Regular Expression) US Phone Number :  222-333-4444 String phone = '222-333-4444'; String WrongPhone = '222-333' //This is the pattern that matches with the above phone number format String regExPhone …

Advertisements

Regular Expression for Words with spaces

Problem: I want to check for the following strings using regExpression: 1) Main-xxxxx-Accepted 2) Main-xxx xxx-Accepted I used the below String regEx = 'Main-[aA-zZ-]*-Accepted'; Pattern.matches(regEx,'Main-SUBMITTED-Accepted')); results in **TRUE** It works fine for Main-SUBMITTED-Accepted. But it fails for a word with spaces (non submitted) Pattern.matches(regEx,'Main-NOT SUBMITTED-Accepted')); results in **FALSE** I tried the below ones. Nothing works String …