I have used the example from http://www.regular-expressions.info/examples.html to validate the following code
while [[ ! $name =~ ^[a-Z][ \t][a-Z]. ]]; do
echo "Please enter your Firstname and Surname e.g Joe Bloggs" # (a)Ask for NAME,TELEPHONE NUMBER,DOB #
read name
echo
done
I am quite simply looking to ensure user enters first and second name with a space any help would be greatly appreciated!
There are several problems with your regex:
a(lowercase) andZ(uppercase). This won’t do what you expect, use[A-Za-z]to check both upper and lowercase letters.+to match one or more characters.$, not.(which matches any single character).Try this:
If you want to validate Uppercased first and last names you could use:
But this would not work with names like
Marty McFlythat don’t follow that rule.