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:
thencode: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]\.)))?$" ]]
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:
not works, suggest put regexp piece piece, working pieces. can't why ^ doesn't work; mentioned in regex(7) man page.code:#!/bin/bash -x name="john doe" if [[ "$name" =~ "^john doe" ]] echo name valid. else echo name invalid. exit 1 fi
Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Regex for valid First and Last name
Ubuntu

Comments
Post a Comment