首先
大小写字母,数字,特殊符号 至少出现一次 8-14位
^(?=.*[A-Za-z])(?=.*\d)(?=.*[!@#\$%^&*])[A-Za-z\d!@#\$%^&*]{8,14}$
(?=...) 是正则表达式中的正向前瞻(positive lookahead)构造。它的作用是在匹配文本的过程中,要求满足括号内规定的条件,但不消耗文本(不包括它在匹配结果中)。它通常用于需要同时满足多个条件的情况。
假设你有一个正则表达式 (?=pattern),其中 pattern 是要查找的条件。
pattern 可以是任何有效的正则表达式,用于描述你要查找的条件。例如,pattern 可以是字母、数字、特殊字符或它们的组合。
当正则表达式引擎在字符串中进行匹配时,它会尝试查找满足 pattern 的部分,但不消耗字符串中的字符。这意味着它只是在当前位置尝试匹配 pattern,而不会移动正则表达式引擎的位置指针。
如果 pattern 成功匹配,正向前瞻就会返回成功(true),否则返回失败(false)。不管成功还是失败,正则表达式引擎都会继续从当前位置向后匹配。
这使得正向前瞻非常适合用于需要同时满足多个条件的匹配情况。例如,在用户名验证的正则表达式中,使用 (?= ...) 来确保用户名中包含字母、数字和特殊字符,而不需要改变正则表达式引擎的位置。这就是 (?= ...) 的具体操作。它帮助你同时检查多个条件,而不需要匹配整个字符串。
解释:
^:表示匹配字符串的开头。
(?=.*[A-Za-z]):使用正向前瞻(positive lookahead)确保字符串中至少包含一个字母。
(?=.*\d):使用正向前瞻确保字符串中至少包含一个数字。
(?=.*[!@#\$%^&*]):使用正向前瞻确保字符串中至少包含一个特殊符号(在此示例中,列举了一些特殊符号,您可以根据需要扩展或更改)。
[A-Za-z\d!@#\$%^&*]{8,14}:匹配包含字母、数字和特殊符号的字符串,长度在8到14个字符之间。
$:表示匹配字符串的结尾。
.* 组合在一起表示匹配任意长度的字符序列,包括空字符串(零字符)。这通常用于灵活地捕获或匹配文本中的内容
- html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>formtitle>
- head>
- <body>
- <form action="web.php" method="post">
- <input type="text" name="name" required pattern="^(?=.*[A-Za-z])(?=.*\d)(?=.*[!@#\$%^&*])[A-Za-z\d!@#\$%^&*]{8,14}$">
- <input type="submit" value="sumbit">
-
- form>
-
- body>
- html>
跨域postmessage首先在windows上配置好虚拟主机,这样可以通过域名来访问
对两个网站分别进行以下配置
- html>
- <html lang="en">
-
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>2023title>
- head>
-
- <body>
- <div>
- <h1>www.example.comh1>
- div>
- body>
- <script>
- window.addEventListener('message', (event) => {
- if (event.origin === 'http://www.example1.com') {
- const cookieData = event.data;
- //处理cookieData
- console.log('Receive message from parent:', cookieData);
- window.parent.postMessage('child message', '*');
- }
- })
- script>
- html>
- html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>iframetitle>
- head>
- <body>
- <iframe id="myIframe" src="http://www.example.com/" frameborder="0">iframe>
- body>
- <script>
- window.onload = function() {
- document.cookie = 'sessionid=example'
- const cookieData = document.cookie
- window.frames[0].postMessage(cookieData, 'http://www.example.com/');
- }
- //添加一个监听事件处理子页面的返回消息
- window.addEventListener('message', (event) => {
- if(event.origin === 'http://www.example.com')
- console.log('Received message from child:', event.data);
- })
- script>
- html>
