html5+JavaScript进行邮箱地址验证


本文摘自PHP中文网,作者巴扎黑,侵删。

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

62

63

64

65

66

67

68

69

70

<!doctype html>

<html>

<head>

<meta charset=utf-8 />

<title>html5 网页特效 邮箱地址验证</title>

<style>

body, input, textarea {

  font-family: "helvetica", arial, helvetica;

}

label {

  display: block;

  float: left;

  clear: left;

  text-align: right;

  width: 100px;

  margin-right: 10px;

}

p { padding: 10px; }

fieldset { border: 1px solid #ccc; margin-bottom: 20px; }

</style>

</head>

<body>

<form>

  <fieldset>

    <legend>some bits about you</legend>

    <p><label for="email">email:</label> <input id="email" name="email" type="email" /></p>

    <p><label for="url">homepage:</label><input id="url" type="url" name="url" required /></p>

    <p><textarea name="comment" cols="100" rows="5" required></textarea></p>

  </fieldset>

  <input type="submit" />

</form>

<script>

// default validation messages

var messages = {

  email: 'be not a legal email address',

  url: 'be not a valid web address',

  comment: 'ye have to specify ye value'

};

var forms = document.getelementsbytagname('form'), i = forms.length, j, el;

while (i--) {

  j = forms[i].length;

  while (j--, el = forms[i][j]) {

    if (el.willvalidate && messages[el.name]) {

      el.setcustomvalidity(messages[el.name]);

    }

  }

}

</script>

<script>

var form = document.getelementsbytagname('form')[0];

form.onsubmit = function (event) {

  var i = this.length, el, cont = true, errors = [];

  while (i--, el = this[i]) {

    if (el.willvalidate) {

      if (!el.validity.valid) {

        errors.push('error with ' + el.name + (el.validationmessage ? ': ' + el.validationmessage: ''));

        cont = false;

      }

    }

  }

   

  if (errors.length) {

    // replace alert with your sexy css教程 info bubbles

    alert(errors.join('n'));

  }

  return cont;

};

</script>

</body>

</html>

以上就是 html5+JavaScript进行邮箱地址验证的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

html页面怎么跟PHP文件连接

html5中文本框输入去除内容提示

javascript与PHP的区别是什么

快速掌握前端开发技巧

js不跳转传值PHP

javascript向PHP传递中文乱码怎么办

html调用PHP

html5+javascript进行邮箱地址验证

linux下html5用户及用户组管理命令详解

一起看看 PHP javascript 语法对照

更多相关阅读请进入《PHP》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...