使用JavaScript进行即时验证 - 不确定从何处开始

时间:2015-03-22 15:29:35

标签: javascript jquery html css email-validation

//PENDING
body {
  font-family: "Raleway", sans-serif;
  font-size: 14pt;
  /* 1em */
  color: white;
  text-align: center;
  background-image: url(./img/bg);
}
#cog {
  margin-top: 5%;
  margin-bottom: -5%;
}
section.hero {
  padding: none;
  margin-left: 10%;
  margin-right: 10%;
}
section.hero h1.heroText {
  font-size: 3em;
  font-weight: 100;
}
section.hero h1.subText {
  font-size: 1.5em;
  font-weight: 100;
}
div.footer {
  font-size: 1.75em;
  font-weight: 100;
  position: absolute;
  bottom: 5px;
  width: 100%;
  text-align: center;
}
input.nicerInput {
  height: 50px;
  width: 25%;
  outline: none;
  background-color: white;
  color: #aaa;
  font-size: 1em;
  text-align: center;
  font-family: "Raleway", sans-serif;
  font-weight: 100;
  display: inline-block;
}
input.submitButton {
  color: white;
  font-family: "Raleway", sans-serif;
  font-weight: 100;
  font-size: 1em;
  height: 56px;
  width: 150px;
  background-color: #5CCF58;
  text-decoration: none;
  text-align: center;
  outline: none;
  border: none;
  display: inline-block;
  position: relative;
  left: -6px;
  top: -1px;
  -webkit-transition: linear all 1s;
  -moz-transition: linear all 1s;
  -mos-transition: linear all 1s;
}
input.submitButton:hover {
  color: inherit;
  background-color: #28CD20;
  -webkit-transition: linear all 0.5s;
  -moz-transition: linear all 0.5s;
  -mos-transition: linear all 0.5s;
}
input.submitButton:active {
  color: inherit;
  background-color: #21B71C;
  -webkit-transition: linear all 0.1s;
  -moz-transition: linear all 0.1s;
  -mos-transition: linear all 0.1s;
}
.errorMsg {
  color: white;
  font-size: 1em;
  margin-left: 10%;
  margin-right: 10%;
  display: none;
}
.fa-spin-custom {
  -webkit-animation: spin 7500ms infinite linear;
  animation: spin 7500ms infinite linear;
}
@-webkit-keyframes spin {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(359deg);
    transform: rotate(359deg);
  }
}
@keyframes spin {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(359deg);
    transform: rotate(359deg);
  }
}
.fa-7x {
  font-size: 7.5em !important;
}
<!DOCTYPE HTML>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, user-scalable=no, width=device-width">
  <meta name="author" content="Olly John">
  <meta name="keywords" content="Stephen John Eyecare, Stephen John Opticians, Worcester, Opticians, Opticions">
  <link rel="stylesheet" type="text/css" href="./css/normalize.css">
  <link rel="stylesheet" type="text/css" href="./css/styles.css">
  <link href='http://fonts.googleapis.com/css?family=Raleway:400,100' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
  <title>Stephen John Eyecare - Coming Soon</title>
</head>

<body>
  <i class="fa fa-7x fa-cog fa-spin-custom" id="cog"></i>
  <section class="hero">
    <h1 class="heroText">We'll be coming <strong>really soon!</strong></h1>
    <h1 class="subText">If you'd like to be notified when we go live, please submit your e-mail address using the field below</h1>
  </section>
  <section class="field">
    <form action="" name="form" method="post">
      <div class="form">
        <input type="text" class="nicerInput" name="input" id="input" placeholder="you@youremail.com">
        <input type="submit" class="submitButton" disabled="true" value="submit" id="sub">
        <br>
        <br>
        <span class="errorMsg" id="empty">Please make sure to enter your e-mail address before submitting it to us. <br></span>
        <span class="errorMsg" id="format">The e-mail address you entered is invalid.  Please enter an e-mail address in the format johndoe@email.com</span>
      </div>
    </form>
  </section>
  <div class="footer">Stephen John Eyecare</div>
  <script src="bower_components/jquery/src/jquery.js"></script>
  <!-- Use jQuery to validate?-->
</body>

</html>

嗨大家好,

我的父亲已经要求我为他的网站制作一个登陆页面,他已经制作了一个登陆页面,他只是想要一些东西放在主机上,所以它不会被浪费,因为他已经购买了空间和域名但是有一个随着网站的发展而受挫,所以他只是让我快速制作一些说明主要网站即将推出的内容,并让人们有能力注册,以便在网站上线时收到通知。
我已经做了所有的前端工作,我已经开始关注'形式'的事情的验证方面,我无法做出正面或反面,所以我希望有人可以提供一些见解,我是什么如果你这么善良,就需要做。
到目前为止,该页面的代码位于代码段中。

提前致谢

1 个答案:

答案 0 :(得分:2)

使用下面的代码验证.. 不要忘记放置主jquery并验证min文件

<!DOCTYPE HTML>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1, user-scalable=no, width=device-width">
  <meta name="author" content="Olly John">
  <meta name="keywords" content="Stephen John Eyecare, Stephen John Opticians, Worcester, Opticians, Opticions">
  <link rel="stylesheet" type="text/css" href="./css/normalize.css">
  <link rel="stylesheet" type="text/css" href="./css/styles.css">
  <link href='http://fonts.googleapis.com/css?family=Raleway:400,100' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
  <title>Stephen John Eyecare - Coming Soon</title>
  <style>
  body {
  font-family: "Raleway", sans-serif;
  font-size: 14pt;
  /* 1em */
  color: #000;
  text-align: center;
  background-image: url(./img/bg);
}
#cog {
  margin-top: 5%;
  margin-bottom: -5%;
}
section.hero {
  padding: none;
  margin-left: 10%;
  margin-right: 10%;
}
section.hero h1.heroText {
  font-size: 3em;
  font-weight: 100;
}
section.hero h1.subText {
  font-size: 1.5em;
  font-weight: 100;
}
div.footer {
  font-size: 1.75em;
  font-weight: 100;
  position: absolute;
  bottom: 5px;
  width: 100%;
  text-align: center;
}
input.nicerInput {
  height: 50px;
  width: 25%;
  outline: none;
  background-color: white;
  color: #aaa;
  font-size: 1em;
  text-align: center;
  font-family: "Raleway", sans-serif;
  font-weight: 100;
  display: inline-block;
}
input.submitButton {
  color: white;
  font-family: "Raleway", sans-serif;
  font-weight: 100;
  font-size: 1em;
  height: 56px;
  width: 150px;
  background-color: #5CCF58;
  text-decoration: none;
  text-align: center;
  outline: none;
  border: none;
  display: inline-block;
  position: relative;
  left: -6px;
  top: -1px;
  -webkit-transition: linear all 1s;
  -moz-transition: linear all 1s;
  -mos-transition: linear all 1s;
}
input.submitButton:hover {
  color: inherit;
  background-color: #28CD20;
  -webkit-transition: linear all 0.5s;
  -moz-transition: linear all 0.5s;
  -mos-transition: linear all 0.5s;
}
input.submitButton:active {
  color: inherit;
  background-color: #21B71C;
  -webkit-transition: linear all 0.1s;
  -moz-transition: linear all 0.1s;
  -mos-transition: linear all 0.1s;
}
.errorMsg {
  color: white;
  font-size: 1em;
  margin-left: 10%;
  margin-right: 10%;
  display: none;
}
.fa-spin-custom {
  -webkit-animation: spin 7500ms infinite linear;
  animation: spin 7500ms infinite linear;
}
@-webkit-keyframes spin {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(359deg);
    transform: rotate(359deg);
  }
}
@keyframes spin {
  0% {
    -webkit-transform: rotate(0deg);
    transform: rotate(0deg);
  }
  100% {
    -webkit-transform: rotate(359deg);
    transform: rotate(359deg);
  }
}
.fa-7x {
  font-size: 7.5em !important;
}
label .error{color:red;}
  </style>
</head>

<body>
  <i class="fa fa-7x fa-cog fa-spin-custom" id="cog"></i>
  <section class="hero">
    <h1 class="heroText">We'll be coming <strong>really soon!</strong></h1>
    <h1 class="subText">If you'd like to be notified when we go live, please submit your e-mail address using the field below</h1>
  </section>
  <section class="field">
    <form action="" name="form"  id="sample_frm" method="post">
      <div class="form">
        <input type="text" class="nicerInput" name="user_email" id="input" placeholder="you@youremail.com">
        <input type="submit" class="submitButton" value="submit" id="sub">
         </div>
    </form>
  </section>
  <div class="footer">Stephen John Eyecare</div>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  <script src="http://jqueryvalidation.org/files/dist/jquery.validate.min.js"></script>
  
 <script>
  $( "#sample_frm" ).validate({
  rules: {
user_email: {
  required: true,
  email: true
}
  },
  messages:
  {
  user_email:{
  required:"Enter email id", //custom error message
  email: "valid email id"
  }
  }
});
</script>
  <!-- Use jQuery to validate?-->
</body>

</html>