#!/bin/bash
rsa_dir="/etc/openvpn/easy-rsa/"
rsa_key_dir="/etc/openvpn/easy-rsa/keys/"
ccd_dir="/etc/openvpn/ccd/"
regex_special_char='[^a-zA-Z_0-9\s]'
cd $rsa_dir
while
read -p "Please can you enter the vpn's username : " username
[[ -z "$username" ]] || [[ ${#username} -lt 2 ]] || [[ ${#username} -gt 15 ]] || [[ "$username" =~ $regex_special_char ]]
do
echo "Your entry must not contain special characters and its length must do between 2-15 characters."
done
echo "ok"
I will wish to add a condition which test if there isn't these characters "� � � �" into the input. I think regex is a good way but my solution doesn't work.
Can you try like the following ( please note i removed capital letters to get different output ):
if [[ "avc123" =~ [a-z0-9���] ]]; then echo matches; else echo "does not match caps"; fi
matches
if [[ "ABC" =~ [a-z0-9���] ]]; then echo matches; else echo "does not match caps"; fi
does not match caps
if [[ "�xu�ti�" =~ [a-z0-9���] ]]; then echo matches; else echo "does not match caps"; fi
matches
# ./user_ovpn.sh
Please can you enter the vpn's username : usertest�
ok
And me I want the output says : "Your entry must not contain special characters and its length must do between 2-15 characters." on all the characters "�����", [^a-zA-Z_0-9\s] works fine with "&~"#'{(-` etc...) but not with accent
if [[ "usertest�" =~ [a-z0-9���] ]]; then echo "Entry should not contain special chars. Reenter correct entry" ; else echo "Does not contain special chars"; fi