how to validate a mobile number in shell script code example
Example 1: how to validate a mobile number in shell script
echo "Enter a phone number as XXXXXXXX: "
read phoneNumber
pat="^[0-9]{8}$"
while [[ ! $phoneNumber =~ $pat ]]
do
echo "Please enter a phone number as XXXXXXXX: "
read phoneNumber
done
echo $phoneNumber
Example 2: how to validate a mobile number in shell script
85625566595
Example 3: how to validate a mobile number in shell script
#!/bin/bash
echo "Enter a phone number as XXXXXXXX: "
read phoneNumber
pat="^[0-9]{8}$"
while [[ ! $phoneNumber =~ $pat ]]
do
echo "Please enter a phone number as XXXXXXXX: "
read phoneNumber
done
echo $phoneNumber