PHP如何檢測密碼長度

來源:互聯網
上載者:User

一 執行個體

1、index.php

<html>
<head>
<metahttp-equiv="Content-Type"content="text/html; charset=gb2312">
<title>檢測字串的長度</title>
<styletype="text/css">
<!--
.style1 {font-size: 12px}
.style2 {
font-family: "華文仿宋";
font-size: 14px;
}
body {
margin-left: 00px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.STYLE3 {color: #FF0000}
-->
</style>
</head>

<body>
<tablewidth="392"height="257"border="0"cellpadding="0"cellspacing="0">
<tr>
<tdalign="left"valign="top"><tablewidth="392"border="0"cellpadding="0"
cellspacing="0">
<tr>
<tdwidth="48"height="113">&nbsp;</td>
<tdwidth="75">&nbsp;</td>
<tdwidth="119">&nbsp;</td>
<tdwidth="72">&nbsp;</td>
<tdwidth="78"align="center"class="style1">&nbsp;</td>
</tr>
<formname="form1"method="post"action="index_ok.php">
<tr>
<tdheight="33"></td>
<tdalign="center"><spanclass="style1">使用者名稱</span>:</td>
<td><inputname="user"type="text"id="user"size="15"></td>
<tdalign="center"><inputname="imageField"type="image"
src="images/btn_dl.jpg"width="50"height="20"border="0"></td>
<td>&nbsp;</td>
</tr>
<tr>
<tdheight="27">&nbsp;</td>
<tdalign="center"><spanclass="style1">密碼</span>:</td>
<td><inputname="pwd"type="password"id="pass"size="15"></td>
<tdcolspan="2"align="left"><spanclass="STYLE3">*&nbsp;密碼長度不能少於6位
</span></td>
</tr>
</form>
<tr>
<tdheight="31">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>

2、index_ok.php

  <?php 
if(strlen($_POST["pwd"])<6){//檢測使用者密碼的長度是否小於6
echo "<script>alert('使用者密碼的長度不得少於6位!請重新輸入'); history.back();</script>";
}
else{
echo "使用者資訊輸入合法!";
}
?>

二 運行結果

int strlen ( string $string )

返回給定的字串 string 的長度。 

參數 

string

需要計算長度的字串。 

傳回值 

成功則返回字串string 的長度;如果string 為空白,則返回0。

來源:http://cakin24.iteye.com/blog/2348826

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.