1

我在我的 asp.net mvc Web 应用程序中有以下视图,可以根据输入的 IP AND/OR MAC 进行搜索:-

@using (Ajax.BeginForm("AdvanceSearchIndex","Home",
new AjaxOptions
{
    HttpMethod = "get",
    InsertionMode = InsertionMode.Replace,
    LoadingElementId = "progress",
    UpdateTargetId = "SearchTable"
}))
{


  <div>
    <span class="f">IP Address </span> 

    @Html.EditorFor(model=>model.ip)
    @Html.ValidationMessageFor(model => model.ip)
</div>

        <div>
    <span class="f">MAC Address </span> 

    @Html.EditorFor(model=>model.mac)
    @Html.ValidationMessageFor(model => model.mac)
</div>@*



    <input class="btn btn-success" type="submit" value="search" /> 

    <img src="~/Content/Ajax-loader-bar.gif" class="loadingimage" id="progress2" />

    }

但是有没有办法检查用户在单击搜索按钮时是否输入了 IP 或 MAC 或两者,我需要一种方法来检查客户端和服务器端的这个。任何人都可以建议吗?

4

1 回答 1

0

验证 IP:http: //jsfiddle.net/kDXmd/

function ValidateIPaddress(ipaddress)   
{  
 if (/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ipaddress))  
  {  
    return (true)  
  }  

    return (false)  
} 

mac地址http://jsfiddle.net/vY95y/

function macAddressValidation(macAdd) 
 {
  var RegExPattern = /^[0-9a-fA-F:]+$/;

  if (!(macAdd.match(RegExPattern)) || macAdd.length != 17) 
  {
   return false;
  }
  else
  {
   return true;
  }
 }
于 2013-10-30T06:21:27.603 回答