-
Notifications
You must be signed in to change notification settings - Fork 0
/
validationfuncs.sh
61 lines (48 loc) · 1004 Bytes
/
validationfuncs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/bash
#---Input Name validation-------------------------------------
function ValInputName {
if [ -z "$1" ]
then
echo "Name field can't be empty"
return 1
elif [[ $1 == *" "* ]]
then
echo "Name shouldn't include spaces"
return 1
elif [[ $1 =~ [^a-zA-Z0-9_] ]]
then
echo "Name shouldn't have special characters"
return 1
elif [[ "$1" =~ ^[0-9] ]]
then
echo "Name shouldn't begin with a number"
return 1
fi
}
function ValDataType {
if [ -z "$1" ]
then
echo " value can't be empty."
return 1
fi
if [[ "$1" =~ ^[0-9]+$ ]]
then
if [ "$2" == "integer" ]
then
return 0
else
echo "The value should be a String."
return 1
fi
fi
if [[ "$1" =~ ^[a-zA-Z0-9_]+$ ]]
then
if [ "$2" == "string" ]
then
return 0
else
echo "The value should be an Integer."
return 1
fi
fi
}