From be94e54dc7cd0eb2e66f25d7def9a873c563564c Mon Sep 17 00:00:00 2001 From: lu <99954486@qq.com> Date: 星期五, 10 一月 2025 09:53:30 +0800 Subject: [PATCH] 细节 --- DevApp/Gs.DevApp/DevFrm/Sys/Frm_PrintInfo.cs | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) diff --git a/DevApp/Gs.DevApp/DevFrm/Sys/Frm_PrintInfo.cs b/DevApp/Gs.DevApp/DevFrm/Sys/Frm_PrintInfo.cs index 74bb5ed..4839956 100644 --- a/DevApp/Gs.DevApp/DevFrm/Sys/Frm_PrintInfo.cs +++ b/DevApp/Gs.DevApp/DevFrm/Sys/Frm_PrintInfo.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Data; using System.Net; +using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Windows.Forms; @@ -206,13 +207,7 @@ txt_port.Focus(); return; } - try - { - IPAddress.Parse(txt_ip.Text); - } - catch - { - txt_ip.Text = ""; + if (!validateIpAddress(txt_ip.Text.Trim())) { MessageBox.Show("璇疯緭鍏ユ纭殑IP鍦板潃"); txt_ip.Focus(); return; @@ -324,5 +319,10 @@ ToolBox.MsgHelper.Warning("鎻愮ず锛�" + ex.Message); } } + private bool validateIpAddress(string ip) + { + string pattern = @"^((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]?)$"; + return Regex.IsMatch(ip, pattern); + } } } \ No newline at end of file -- Gitblit v1.9.3