幾個常用的js判斷方法 CheckForm
1
function isInt(intValue){
2
var intPattern=/^0$|^[1-9]\d*$/; //整數的正則表達式
3
result=intPattern.test(intValue);
4
return result;
5
}
6
7
function isFloat(floatValue){
8
var floatPattern=/^0(\.\d+)?$|^[1-9]\d*(\.\d+)?$/; //小數的正則表達式
9
result=floatPattern.test(floatValue);
10
return result;
11
}
12
function isEmail(emailValue){
13
var emailPattern=/^[^@.]+@([^@.]+\.)+[^@.]+$/; //郵箱的正則表達式
14
result=emailPattern.test(emailValue);
15
return result;
16
}
17
function isNum(obj,alt){
18
var numPattern=/^\d*$/; //數字的正則表達式
19
result=numPattern.test(obj.value);
20
if(!result){
21
alert(alt);
22
obj.focus();
23
}
24
return result;
25
}
26
27
function isChar(obj,alt){
28
var charPattern=/^[a-zA-Z]*$/; //是否為字母
29
result=charPattern.test(obj.value);
30
if(!result){
31
alert(alt);
32
obj.focus();
33
}
34
return result;
35
}
36
37
function isCharNum(flagValue){
38
var flagPattern=/^[a-zA-Z0-9]*$/; //是否為字母和數字(傳真標識符)
39
result=flagPattern.test(flagValue);
40
return result;
41
}
42
function isBlank(obj,alt){
43
if(obj.value==""){
44
alert(alt);
45
obj.focus();
46
return true;
47
}
48
return false;
49
}
50

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
