JavaScript mailbox verification - regular verification

Mazey 2021-02-23 16:00:46
javascript mailbox verification regular verification


One 、RegExp

1.1 establish RegExp object

new RegExp(" Mandatory , Regular expressions "," Optional , Matching mode g,i,m")

1.2 RegExp Object method

  • test: Retrieve the specified value in the string , return True or False.
  • exec: Retrieve the specified value in the string , Returns the value found , No rules null.
  • complie: Used to change regular expressions , Or add or delete matching patterns .

1.2.1 test()

var r1 = new RegExp('world');
console.log(r1.test('Hello, world!')); //true
console.log(r1.test('Hello, World!')); //false
var r2 = new RegExp('world', 'i'); // Case insensitive
console.log(r2.test('Hello, World!')); //true
var r3 = new RegExp(/world/i); // Abbreviation
console.log(r3.test('Hello, World!')); //true

1.2.2 exec()

var r1 = new RegExp('world');
console.log(r1.exec('Hello, world!')); //['world']
console.log(r1.exec('Hello, World!')); //null
var r2 = new RegExp('world', 'i'); // Case insensitive
console.log(r2.exec('Hello, World!')); //['world']
var r3 = new RegExp(/world/i); // Abbreviation
console.log(r3.exec('Hello, World!')); //['world']
var r4 = new RegExp('o');
console.log(r4.exec('Hello, World!')); //['o']
var r5 = new RegExp('o', 'gi');
console.log(r5.exec('Hello, WOrld!')); //['o']
console.log(r5.lastIndex); //5 Match the position of the first character of the text ,o by 4, The next position is 5
console.log(r5.exec('Hello, WOrld!')); //['O'] Match the first o After the call continues to match
console.log(r5.lastIndex); //9
console.log(r5.exec('Hello, WOrld!')); //null No match returned null
console.log(r5.lastIndex); //0 lastIndex Reset to 0

1.2.3 complie()

var r1 = new RegExp('world');
console.log(r1.exec('Hello, world!')); //['world']
r1.compile('o');
console.log(r1.exec('Hello, World!')); //['o']
r1.compile('m');
console.log(r1.exec('Hello, World!')); //null
var r2 = new RegExp('world');
console.log(r2.test('Hello, world!')); //true
r2.compile('mazey');
console.log(r2.test('Hello, world!')); //false

Two 、 Regular expressions

  • ^$: Represents the beginning and end of the match value .
  • +1+, One or more .
  • *0 / +, Zero or more .
  • ?0 / 1, Zero or one .
  • {1,2}:1 <= length <= 2, length .
  • (): Represents a group of expressions .
  • []: The range of characters to match , I understand it as a block , Lots of blocks in one group () Inside .

3、 ... and 、 Example

<form action="">
Input :
<input type="text" name="mazey" id="mazey" placeholder=" Please enter email address ">
<input type="button" value=" verification " onclick="check();">
</form>
<script>
function check(){
var reg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$"); // Regular expressions
var obj = document.getElementById("mazey"); // Object to verify
if(obj.value === ""){ // Input cannot be empty
alert(" Input cannot be empty !");
return false;
}else if(!reg.test(obj.value)){ // Regular validation failed , Wrong format
alert(" Verification failed !");
return false;
}else{
alert(" adopt !");
return true;
}
}
</script>

appendix

Read the original :https://blog.mazey.net/589.html

版权声明
本文为[Mazey]所创,转载请带上原文链接,感谢
https://javamana.com/2021/02/20210223155427055v.html

  1. Spring can still play like this! Ali's new spring product has successfully overturned my understanding of spring!
  2. IntelliJ idea can also draw mind maps. It's really the strongest ide!
  3. JavaScript performance optimization [inline cache] V8 engine features
  4. linux 配置java环境
  5. linux find 查找文件
  6. 深入理解 Web 协议 (三):HTTP 2
  7. IntelliJ IDEA 相关问题记录
  8. Deep understanding of Web protocol (3): http 2
  9. 深入理解 Web 协议 (三):HTTP 2
  10. 腾讯IEG开源AI SDK:自动化测试吃鸡、MOBA类游戏
  11. Mysql Command
  12. Configuring Java environment with Linux
  13. Find files in Linux
  14. docker-Dockerfile 创建镜像
  15. Redis Cluster
  16. 深入理解 Web 协议 (三):HTTP 2
  17. JavaScriptBOM操作
  18. JavaScriptBOM操作
  19. Deep understanding of Web protocol (3): http 2
  20. Record of IntelliJ idea related problems
  21. Deep understanding of Web protocol (3): http 2
  22. Tencent IEG open source AI SDK: automatic testing of chicken eating and MoBa games
  23. Mysql Command
  24. Docker dockerfile create image
  25. Redis Cluster
  26. 死磕Spring之IoC篇 - 文章导读
  27. Deep understanding of Web protocol (3): http 2
  28. JavaScript BOM operation
  29. JavaScript BOM operation
  30. 死磕Spring之IoC篇 - 文章导读
  31. k8s node 操作与维护
  32. k8s 证书更新
  33. 【Java面试题第三期】JVM中哪些地方会出现内存溢出?出现的原因是什么?
  34. HashMap连环问你能答出几道?
  35. k8s-cronjob
  36. k8s-cert
  37. 头条面试官:说说Kafka的消费者提交方式,怎么实现的
  38. 什么是HTTPS以及如何实施HTTPS?
  39. Spring: an introduction to IOC
  40. Spring: an introduction to IOC
  41. Operation and maintenance of k8s node
  42. K8s certificate update
  43. vue使用sdk进行七牛上传
  44. k8s-dns
  45. JavaScript 邮箱验证 - 正则验证
  46. k8s-dashboard
  47. HashMap连环问你能答出几道?
  48. Where does memory overflow occur in the JVM? What are the reasons for this?
  49. How many questions can you answer?
  50. k8s-cronjob
  51. spring注解--Transactional
  52. k8s-cert
  53. Will the Spring Festival holiday be extended to February 27 in 2021? Here comes the response
  54. Headline Interviewer: talk about Kafka's consumer submission method, how to achieve it
  55. 【k8s集群】搭建步骤
  56. k8s-kubeadm
  57. k8s-etcd
  58. What is HTTPS and how to implement it?
  59. Java中使用HashMap改进查找性能
  60. maven发布jar包运行时找不到类问题