IPV4地址验证的正则表达式

IPV4地址验证的正则表达式

本文介绍了IPV4地址验证的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我需要一些小帮助来为IPV4地址验证创建正则表达式。

我的验证字符串如下所示..

Hello,

I need a small help in creating a regular expression for IPV4 address validation.
My validation string is as below..

http://IP:PORT/



我试过的内容如下: 。


What I have tried is given below...

private bool IsUrlValid(string url)
 {
   Regex urlRx = new Regex(@"^https?://(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/$", RegexOptions.IgnoreCase);
  return urlRx.IsMatch(url);
 }





使用此代码,我可以完美地验证没有端口的IPV4地址;但是我想修改它以接受端口号。

任何对此的帮助将不胜感激。

提前致谢



With this code, I could perfectly validate an IPV4 address without port; But I want to modify this to accept port number also.
Any help on this would be greatly appreciated.
Thanks in advance

推荐答案





使用此代码,我可以完美地验证没有端口的IPV4地址;但我想修改它以接受端口号。

对此的任何帮助将不胜感激。

提前致谢



With this code, I could perfectly validate an IPV4 address without port; But I want to modify this to accept port number also.
Any help on this would be greatly appreciated.
Thanks in advance


private bool IsUrlValid(string url)
{
    Regex urlRx = new Regex(@"^https?://(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?):?(6553[0-5]|655[0-2]\d|65[0-4]\d{2}|6[0-4]\d{3}|[1-5]\d{4}|[1-9]\d{0,3})/






谢谢

Sebastian



Thanks
Sebastian


这篇关于IPV4地址验证的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 19:36