xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

regex & form validation & phone

regex & form validation

https://regexper.com/
https://gitlab.com/javallone/regexper-static
https://github.com/javallone/regexper-static


/^(\w+)\:\/\/([^\/]+)\/(.*)$/

// telephone
/^0[0-9]{2,3}-[0-9]{3, 4}-[0-9]{4}$/

0
021 8888 8888
0371 6666 7777
0370 567 8888

// cell phone / mobile phone
/^1[0-9]{2}-[0-9]{4}-[0-9]{4}$/

1
181 3333 7777
177 6666 8888

https://regexper.com/#%2F^(\w%2B)\%3A\%2F\%2F([^\%2F]%2B)\%2F(.*)%24%2F


https://element.eleme.io/#/zh-CN/component/form#biao-dan-yan-zheng

https://element.eleme.io/#/zh-CN/component/input#input-attributes

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#Form_<input>_types
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/tel


image
image

special-quantifier-range

no space between the comma!

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#special-quantifier-range


    regexSpaceBug() {
        let pattern = /0[0-9]{2, 3}-[0-9]{3, 4}-[0-9]{4}/;
        // /0[0-9]{2, 3}-[0-9]{3, 4}-[0-9]{4}/
        pattern.test("021-6666-8888");
        // false
        pattern = /0[0-9]{2,3}-[0-9]{3,4}-[0-9]{4}/;
        // /0[0-9]{2,3}-[0-9]{3,4}-[0-9]{4}/
        pattern.test("021-6666-8888");
        // true
        pattern.test("0371-6666-8888");
        // true
        pattern.test("0370-333-8888");
        // true
    },



    telephoneChange() {
        let value = this.$data.form.telephoneNum;
        console.log(`telephoneNum value =`, value);
    },
    phoneChange() {
        let value = this.$data.form.phoneNum;
        console.log(`phoneNum value =`, value);
    },
    telephoneInput() {
        const pattern = /^0[0-9]{2,3}-[0-9]{3,4}-[0-9]{4}$/;
        let value = this.$data.form.telephoneNum;
        if (pattern.test(value)) {
            this.$data.show.telephoneNum = false;
        } else {
            if(value !== "") {
                this.$data.show.telephoneNum = true;
                this.$data.error.telephoneNum = `输入的电话号码不符合格式, ${pattern.toString()}`;
            } else {
                this.$data.show.telephoneNum = false;
            }
        }
    },
    phoneInput() {
        const pattern = /^1[0-9]{2}-[0-9]{4}-[0-9]{4}$/;
        let value = this.$data.form.phoneNum;
        if (pattern.test(value)) {
            this.$data.show.phoneNum = false;
        } else {
            if(value !== "") {
                this.$data.show.phoneNum = true;
                this.$data.error.phoneNum = `输入的手机号码不符合格式, ${pattern.toString()}`;
            } else {
                this.$data.show.phoneNum = false;
            }
        }
    },


email validation

https://stackoverflow.com/questions/46155/how-to-validate-an-email-address-in-javascript
https://www.sitepoint.com/javascript-validate-email-address-regex/

https://www.w3resource.com/javascript/form/email-validation.php
https://www.regextester.com/19


posted @   xgqfrms  阅读(251)  评论(1编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2015-11-19 html页面嵌入视频error解决方案: Vimeo : 高清视频播客网站
2015-11-19 mobirise for website builder
2015-11-19 Windows 10 自带 free 屏幕截图/录像软件 Game Bar! 不仅仅是game-游戏呦! 高清晰,高保真,perfect!不仅仅是游戏呦!
点击右上角即可分享
微信分享提示