首页 > 作文

PHP jQuery表单,带验证具体实现方法

更新时间:2023-04-06 23:17:20 阅读: 评论:0

email检测,密码重复检测,可以用于表单发送的各种环境,例如发送反馈,注册帐号

复制代码 代码如下:

<div id=”container”>

<?if( ist($_post[‘nd’]) && (!validatename($_post[‘name’]) || !validateemail($_post[’email’]) || !validatepasswords($_post[‘pass1’], $_post[‘pass2’]) || !validatemessage($_post[‘message’]) ) ):?>

<div id=”error”>

<ul>

<?if(!validatename($_post[‘name’])):?>

<li><strong>invalid name:</strong> we want names with more than 3 letters!</li>

<?endif?>

<?if(!validateemail($_post[’email’])):?>

<li><strong>invalid e-mail:</strong> stop cowboy! type a valid e-mail plea :p</li>

<?endif?>

<?if(!validatepasswords($_post[‘pass1’], $_post[‘pass2’])):?>

<li><strong>passwords are invalid:</strong> passwords doesn’t match or are invalid!</li>

<?endif?>

<?if(!validatemessage($_po高考满分作文精选st[‘message’])):?>

<li><strong>ivalid message:</strong> type a message with at least with 10 lette传奇行会个性名字rs</li>

<?endif?>

</ul>

</div>

<?elif(ist($_post[‘nd’])):?>

<div id=”error” class=”valid”>

<ul>

<li><strong>congratulations!</strong> all fields are ok ;)</li>

</ul>

</div>

<?endif?>

<form method=”post” id=”customform” action=””>

<div>

<label for=”name”>name</label>

<input id=”name” name=”name” type=”text” />

<span id=”nameinfo”>what’s your name?</span>

</div>

<div>

<label for=”email”>e-mail</label>

<input id=”email” name=”email” type=”text” />

<span id=”emailinfo”>valid e-mail plea, you will need it to log in!</span>

</div>

<div>

<label for=”pass1″>password</label>

<input id=”pass1″ name=”pass1″ type=”password” />

<span id=”pass1info”>at least 5 c官场小说排行haracters: letters, numbers and ‘_'</span>

</div>

<div>

<label for=”pass2″>confirm password</label>

<input id=”pass2″ name=”pass2″ type=”password” />

<span id=”pass2info”>confirm password</span>

</div>

<div>

<label for=”message”>message</label>

<textarea id=”message” name=”message” cols=”” rows=””></textarea>

</div>

<div>

<input id=”nd” name=”nd” type=”submit” value=”nd” />

</div>

</form>

</div>

validation.php

复制代码 代码如下:

<?php

function validatename($name){

//if it’s not valid

if(strlen($name) < 4)

return fal;

//if it’s valid

el

return true;

}

function validateemail($email){

return ereg(“^[a-za-z0-9]+[a-za-z0-9_-]+@[a-za-z0-9]+[a-za-z0-9.-]+[a-za-z0-9]+.[a-z二级vb]{2,4}$”, $email);

}

function va松果播音lidatepasswords($pass1, $pass2) {

//if doesn’t match

if(strpos($pass1, ‘ ‘) !== fal)

return fal;

//if are valid

return $pass1 == $pass2 && strlen($pass1) > 5;

}

function validatemessage($message){

//if it’s not valid

if(strlen($message) < 10)

return fal;

//if it’s valid

el

return true;

}

?>

本文发布于:2023-04-06 23:17:18,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/ff0260603af0b4e5c0003f92a980f129.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:PHP jQuery表单,带验证具体实现方法.doc

本文 PDF 下载地址:PHP jQuery表单,带验证具体实现方法.pdf

标签:代码   松果   帐号   行会
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图