使用掩码验证IP的HTML5模式 [英] HTML5 pattern for validating IP with mask

查看:76
本文介绍了使用掩码验证IP的HTML5模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个HTML5模式,用于将输入文本与IP地址和掩码一起使用,如下所示:

I'm trying to create a HTML5 pattern for input text with and IP address and mask together, like this:

10.120.15.30/28或172.181.30.0/24

10.120.15.30/28 or 172.181.30.0/24

我在 http://html5pattern.com/Miscs 上找到了一个html5模式,但仅适用于不带掩码的IPv4

I found one html5 pattern at http://html5pattern.com/Miscs but is only for IPv4 without mask

((^|\.)((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))){4}$

我尝试在

    (\/).((([0-2])|(0-9))|(3[1-2])) 

但不起作用.有什么想法吗?

but is not working. Any ideas?

推荐答案

((^|\.)((25[0-5])|(2[0-4]\d)|(1\d\d)|([1-9]?\d))){4}/(?:\d|[12]\d|3[01])$

演示.

我只是在您提供的模式中添加了/(?:\d|[12]\d|3[01]):

I simply added /(?:\d|[12]\d|3[01])to the pattern you provided:

/          // match a slash
(?:        // then match either one of
    \d     // a single digit
|
    [12]\d // any number from 10 to 29
|
    3[01]  // 30 or 31
)

这篇关于使用掩码验证IP的HTML5模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆