首页 > 其他分享 >使用正则表达式验证用户名和密码

使用正则表达式验证用户名和密码

时间:2023-10-12 15:45:42浏览次数:37  
标签:用户名 验证 正则表达式 50% innerHTML getElementById var calc document

学习Java开发mis系统

一开始总的有个页面来登录吧,可以输入用户名和密码,用到使用正则表达式验证用户名和密码。

马上安排!

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>用户登录</title>
<script language="javascript">
function setfocus(){
document.loginForm.PersonName.focus();
}
function checkForm(){
var theForm=document.loginForm;
if(theForm.PersonName.value==""){
document.getElementById("nameId").innerHTML="请输入用户名!";
}
else if(theForm.PersonPwd.value==""){
document.getElementById("passwordId").innerHTML="请输入密码!";
}
else{
var nameStr=document.getElementById("textId").value.trim();
var pwdStr=document.getElementById("pwId").value;
var nameReg=/^[\u4E00-\u9FA5A0-9a-zA-Z_]{2,16}$/;
var pwdReg=/^(\w){6,20}$/;
if(!nameReg.test(nameStr)){
document.getElementById("nameId").innerHTML="请输入2至16个中文字母、数字或者下划线!";
}
else if(!pwdReg.test(pwdStr)){
document.getElementById("passwordId").innerHTML="请输入6至20个字母、数字或者下划线!";
}
else{
theForm.submit();
}
}
}
function blurHandle(){
var theForm=document.loginForm;
if(theForm.PersonName.value!=""){
var str=document.getElementById("textId").value.trim();
var nameReg=/^[\u4E00-\u9FA5A0-9a-zA-Z_]{2,16}$/;
if(!nameReg.test(str))
document.getElementById("nameId").innerHTML="请输入2至16个中文字母、数字或者下划线!";
else
document.getElementById("nameId").innerHTML="";
}
if(theForm.PersonPwd.value!=""){
var str=document.getElementById("pwId").value;
var pwdReg=/^(\w){6,20}$/;
if(!pwdReg.test(str))
document.getElementById("passwordId").innerHTML="请输入6至20个字母、数字或者下划线!";
else
document.getElementById("passwordId").innerHTML="";
}
}
</script>
<style type="text/css">
.formposition1{
position:absolute;
left:calc(50% - 88px - 53px);
top:calc(50% - 20px);
}
.formposition2{
position:absolute;
left:calc(50% - 88px);
top:calc(50% - 23px);
}
.formposition3{
position:absolute;
left:calc(50% - 88px + 186px);
top:calc(50% - 20px);
}

.formposition11{
position:absolute;
left:calc(50% - 88px - 53px);
top:calc(50% - 20px + 26px);
}
.formposition22{
position:absolute;
left:calc(50% - 88px);
top:calc(50% - 23px + 26px);
}
.formposition33{
position:absolute;
left:calc(50% - 88px + 186px);
top:calc(50% - 20px + 26px);
}

.formposition44{
position:absolute;
left:calc(50% - 88px);
top:calc(50% - 23px + 26px + 26px);
}
#textId{
width:176px;
height:16px;
}
#pwId{
width:176px;
height:16px;
}
#buttonId{
width:91px;
height:23px;
}
}
</style>
</head>
<body onl oad="javascript:setfocus()">
<form action="GetPersonData" name="loginForm" method="post" accept-charset="gb2312">
<div class="formposition1">
<label for="textId">用户名</label>
</div>
<div class="formposition2">
<input type="text" id="textId" name="PersonName" value="" onBlur="javascript:blurHandle()">
</div>
<div class="formposition3">
<span style="color:red; white-space:nowrap" id="nameId"></span>
</div>

<div class="formposition11">
<label for="pwId">密&emsp;码</label>
</div>
<div class="formposition22">
<input type="password" id="pwId" name="PersonPwd" value="" onBlur="javascript:blurHandle()">
</div>
<div class="formposition33">
<span style="color:red" id="passwordId"></span>
</div>
<div class="formposition44">
<input type="button" id="buttonId" value="提交 " onclick="javascript:checkForm()">
</div>
</form>
</body>
</html>

标签:用户名,验证,正则表达式,50%,innerHTML,getElementById,var,calc,document
From: https://www.cnblogs.com/Imageroom/p/17759654.html

相关文章

  • 正则表达式
     ......
  • 【Azure Developer】在App Service上放置一个JS页面并引用msal.min.js成功获取AAD用户
    问题描述在AppService上放置一个JS页面并引用msal.min.js,目的是获取AAD用户名并展示。问题解答示例代码<!DOCTYPEhtml><html><head><title>AzureService</title></head><scripttype="text/javascript"src="https://alcdn.msauth.net/......
  • 【Azure Developer】在App Service上放置一个JS页面并引用msal.min.js成功获取AAD用户
    问题描述在AppService上放置一个JS页面并引用msal.min.js,目的是获取AAD用户名并展示。问题解答示例代码<!DOCTYPEhtml><html><head><title>AzureService</title></head><scripttype="text/javascript"src="https://alcdn.msauth.net/lib/1.......
  • 天合光能组件质量怎么样?至尊组件双面增益达8.82%,高可靠性再获验证
     近日,第三方权威检测认证机构鉴衡进行的极端气候户外实证报告出炉:天合光能至尊600W+系列组件在张北常年多风天气下,运行表现优异,EL图像无缺陷,与至尊600W+单面组件相比,双面组件发电增益高达8.82%。再度证实至尊组件应用于常年大风地区光伏电站的卓越可靠性,用品质护航客户价值。......
  • JavaScript之正则表达式
    正则表达式(RegExp)正则表达式不是JS独有的内容,大部分语言都支持正则表达式JS中正则表达式使用得不是那么多,我们可以尽量避免使用正则表达式在JS中,正则表达式就是RegExp对象,RegExp对象用于将文本与一个模式匹配正则表达式(regularexpressions,规则表达式)正则表达式用来定......
  • Jmeter - 参数关联(正则表达式)
     前言:工具久没用是真的会生疏,补补笔记加深记忆. 一、什么时候需要关联?1. 服务器返回的动态变化而且对业务有影响的需要关联。2. 回放脚本看是否正确,检查下脚本,是否有动态数据影响3.一大串字符串,每次请求参数是否有变化4. 可以找开发问问,接口是开发做的,最清楚了 ......
  • 表单验证案例(附源码)
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><title>用户注册</title><style&g......
  • 如何在JavaScript中验证电子邮件地址?
    内容来自DOChttps://q.houxu6.top/?s=如何在JavaScript中验证电子邮件地址?我想在将用户输入发送到服务器或尝试向其发送电子邮件之前,在JavaScript中检查它是否是电子邮件地址,以防止最基本的拼写错误。我该如何实现?使用正则表达式可能是在JavaScript中验证电子邮件地址的最......
  • .net core linux下使用SkiaSharp实现图形验证码
    linux下使用c#自带的获取验证码需要安装图形处理插件比较麻烦 安装nugit依赖SkiaSharp.NativeAssets.Linux.NoDependencies  添加helper类SkiaSharpValidateCodeHelper.csusingSkiaSharp;usingSystem.Text;namespaceVerifyCode.Helpers{publicclassSkia......
  • linux 下保存 git 用户名密码
    1.linuxgit保存用户名密码参考地址:https://stackoverflow.com/questions/35942754/how-can-i-save-username-and-password-in-gitgitconfig--globalcredential.helperstore......