Skip to main content

Thread: Regex for valid First and Last name


i have regex i'd implement , believe should working , have tested on various websites have regex testers says name invalid.

#!/bin/bash -x

echo enter users first , last name.
read name

code:
code:
if [[ "$name" =~ "^((?:[a-z](?:('|(?:[a-z]{1,3}))[a-z])?[a-z]+)|(?:[a-z]\.))(?:([ -])((?:[a-z](?:('|(?:[a-z]{1,3}))[a-z])?[a-z]+)|(?:[a-z]\.)))?$" ]]
then
echo name valid.
else
echo name invalid.
exit 1
fi


if enter jon doe should valid.

quote posted woodson2 view post
i have regex i'd implement , believe should working , have tested on various websites have regex testers says name invalid.

#!/bin/bash -x

echo enter users first , last name.
read name

code:
code:
if [[ "$name" =~ "^((?:[a-z](?:('|(?:[a-z]{1,3}))[a-z])?[a-z]+)|(?:[a-z]\.))(?:([ -])((?:[a-z](?:('|(?:[a-z]{1,3}))[a-z])?[a-z]+)|(?:[a-z]\.)))?$" ]]
then
echo name valid.
else
echo name invalid.
exit 1
fi


if enter jon doe should valid.
i'm not expert on regexps bash supports, , didn't try understand long one, went other direction:

code:
#!/bin/bash -x    name="john doe"    if [[ "$name" =~ "^john doe" ]]   echo name valid.  else  echo name invalid.  exit 1  fi
not works, suggest put regexp piece piece, working pieces. can't why ^ doesn't work; mentioned in regex(7) man page.


Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Regex for valid First and Last name


Ubuntu

Comments

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

After Effect warning: A problem occurred when processing OpenGL commands

Preconditions Failed. - Joomla! Forum - community, help and support