如何验证字符串是否为字母数字组合(包含字母和数字)#linux#Bash 猛击
我试过这个:如何验证字符串是否为字母数字组合(包含字母和数字)#linux#Bash 猛击,linux,Linux,我试过这个: a="abc123" if ! [[ $a =~ [^a-zA-Z0-9] ]]; then echo " a is alphanumeric" else echo " a is not alphanumeric" 但是这个函数验证字符串是只有字母还是只有数字,不是两者都有,我不知道如何使它工作。我查了一下谷歌,但没发现什么 #!/bin/bash a="abc123" if ([[ $a =~ [a-
a="abc123"
if ! [[ $a =~ [^a-zA-Z0-9] ]]; then
echo " a is alphanumeric"
else
echo " a is not alphanumeric"
但是这个函数验证字符串是只有字母还是只有数字,不是两者都有,我不知道如何使它工作。我查了一下谷歌,但没发现什么
#!/bin/bash
a="abc123"
if ([[ $a =~ [a-zA-Z] ]] && [[ $a =~ [0-9] ]]); then
echo " a is alphanumeric"
else
echo " a is not alphanumeric"
fi