Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
43 lines (28 loc) · 914 Bytes

File metadata and controls

43 lines (28 loc) · 914 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>GetElementById</title>
<script type="text/javascript">
/*
需求:当用户点击了校验按钮,要获取输入框内容,然后验证是否合法
校验规则:必须由字母、数字、下划线组成 并且长度是5-12位
*/
function onclickFun() {
var usernameObj=document.getElementById("username");
var userNameText=usernameObj.value;
alert(userNameText);
var patt=/^\w{5,12}$/;
if(patt.test(userNameText)){
alert("用户名合法");
}else {
alert("用户名不合法!");
}
}
</script>
</head>
<body>
用户名:<input type="text" id="username" value="汪方晨">
<button onclick="onclickFun()">校验</button>
</body>
</html>
Morty Proxy This is a proxified and sanitized view of the page, visit original site.