2010-07-06 7 views
13

JQuery 용 IP 마스크 플러그인이 있습니까? Masked Input Plugin을 시도했지만 12 자리 미만의 IP 주소는 사용하지 않습니다. 그럼 난 meioMask 시도하고 12 미만의 숫자로 작동하지 않습니다. 어떤 제안? 마스크 입력 플러그인에서JQuery IP 마스크 플러그인이 필요합니다.

+0

"12 자리 미만으로 작동하지 않는다"는 의미는 무엇입니까 ?? 몇 가지 예를 보여 주시겠습니까 ??? – Kai

+0

10.10.10.10 <12 digits – HyderA

+0

IPv6가 더 이상 IPv4와 호환되지 않으므로이 문제가 있습니까? 또한 합리적인 질문으로 합리적인 답을 얻을 수없는 일을하는 데 도움이 될 몇 가지 예제/코드를 게시하십시오. 그래서 내가 말할 수있는 것은 42입니다. – Sphvn

답변

10
+0

설명서가 없습니다. 노력하고 노력하는 것은 고통입니다. 인스턴스에 대한 값 검색. – HyderA

+0

링크 해제 ... 아니요 404이지만 빈 페이지. – user9645

+0

그동안 시도해보세요. http://web.archive.org/web/20140219174935/http://mlntn.com/2009/12/30/jquery-ip-address-plugin/ – Philippe

1

작업 예 - http://digitalbush.com/projects/masked-input-plugin/


는 12 자 미만 :

jQuery(function($){ 
    $("#date").mask("99/99/9999"); 
    $("#phone").mask("(999) 999-9999"); 
    $("#tin").mask("99-9999999"); 
    $("#ssn").mask("999-99-9999"); 
}); 

그들은 작업을 한 예를 완벽하게 실행?

무엇이 문제이며 더 이상 심도있는 정보를 게시 할 수 있습니까?

jQuery(function($){ 
    $("#MyElementID").mask("10.0.0.0"); //Does this not work? 
}); 

각 입력란에서 1 ~ 3 자리를 카운터하고 있습니까?

예를 들어.

$("#MyElementID").mask("1.0.0.0"); //this 
$("#MyElementID").mask("10.10.10.10"); //or this 
$("#MyElementID").mask("100.100.100.100"); //or this 

당신이 그 후에있는 경우 숫자를 변화 할 수 있도록, 입력 상자를 워터 마킹보다는 마스크를 적용하여 간단하게 뭔가를 시도 할 수 있습니다

당신은 ... 당신이 도움을받을 수 있습니다 더 자세한 설명이 될 경우 그 을 입력 할 수 있습니다. 참조 JQuery와 - 워터 마크 - 당신은이 게시물에서 답변을 찾을 수 있습니다

+1

예, 각 필드에 1-3 자리 숫자가 필요합니다. 특정 숫자는 필요하지 않습니다. 워터 마크 플러그인이 어떻게 도움이 될지 모르겠습니다. – HyderA

+0

누군가는 이것을 downvoting하는 이유를 설명 해주시겠습니까? – Sphvn

+0

나는 downvote하지 않았지만 나는 1-3 자릿수를 마스킹을 허용하는 방법을 알아야합니다. – HyderA

1

i fou 차이 당신은 플러그인

function fnValidateIPAddress(ipaddr) { 
    //Remember, this function will validate only Class C IP. 
    //change to other IP Classes as you need 
    ipaddr = ipaddr.replace(/\s/g, "") //remove spaces for checking 
    var re = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/; //regex. check for digits and in 
              //all 4 quadrants of the IP 
    if (re.test(ipaddr)) { 
     //split into units with dots "." 
     var parts = ipaddr.split("."); 
     //if the first unit/quadrant of the IP is zero 
     if (parseInt(parseFloat(parts[0])) == 0) { 
      return false; 
     } 
     //if the fourth unit/quadrant of the IP is zero 
     if (parseInt(parseFloat(parts[3])) == 0) { 
      return false; 
     } 
     //if any part is greater than 255 
     for (var i=0; i<parts.length; i++) { 
      if (parseInt(parseFloat(parts[i])) > 255){ 
       return false; 
      } 
     } 
     return true; 
    } else { 
     return false; 
    } 
} 
3

이 설명서 나 방법에 대해 걱정할 필요 팽 플러그인을 사용하거나하지 않고, 여러 개의 입력을 조작 할 수있는 쉬운 방법을 원하는 사람을위한 그러나 이전 게시물을 설치할 필요하지는 , 여기 당신을 위해 모든 것을하는 간단한 클래스 선택기 메서드가 있습니다. 그것의 IPv4 만하지만 당신의 요구가 꽤 간단하다는 소리. D이 버전은 CIDR 표기법을 지원합니다 (예 : 192.168.1.1/16)에만 허용

//jQuery 1.9+ selector pattern, 
//To get working with an older version 
//Swap first line to $(".ip").bind('keydown',function(e){ 
//To get working with jQuery versions support .live 
//$(".ip").live('keydown',function(e){ 
$(document).on('keydown',".ip",function(e){ 
    var code = e.keyCode || e.which; 
    var sections = $(this).val().split('.'); 
    //Only check last section! 
    var isInt  = ((code >= 48 && code <= 57) || (code >= 96 && code <= 105)); 
    var hasSlash = $(this).val().indexOf("/") == -1; 
    if(isInt){ 
     if(hasSlash){ 
      if(sections.length < 4){ 
       //We can add another octet 
       var val = parseInt(sections[sections.length-1]+String.fromCharCode(code)); 
       if(val > 255 || parseInt(sections[sections.length-1]) == 0){ 
        $(this).val($(this).val()+"."+String.fromCharCode(code)); 
        return false; 
       } 
       return true; 
      } else { 
       //Lets prevent string manipulations, our string is long enough 
       var val = parseInt(sections[sections.length-1]+String.fromCharCode(code)); 
       if(val > 255 || parseInt(sections[sections.length-1]) == 0){ 
        return false; 
       } 
       return true; 
      } 
     } else { 
      var cidr_split = $(this).val().split('/'); 
      var target_val = parseInt(cidr_split[1]+String.fromCharCode(code)); 
      return (target_val < 33 && target_val.toString().length < 3 && parseInt(cidr_split[1]) != 0); 
     } 
    } else if(code == 191){ 
     //CIDR Slash 
     return ($(this).val().indexOf("/") == -1); 
    } else if(code == 8 || code == 46 || code == 9 || code == 13){ 
     return true; 
    } 
    return false 
}); 

이해를 위해이를 분해하기 위해, 당신은 당신의 입력의 클래스 "IP"를 결합, 자동으로 나머지를 처리합니다 유효한 주소를 입력 할, CIDR 당신이 내가 필요, 2 해결 될 생각하는 뭔가 (테스트되지 않음) 다음 코드 나는 두 가지 목적 1) 여기의 코드를 제공하고

//jQuery 1.9+ selector pattern, 
//To get working with an older version 
//Swap first line to $(".ip").bind('keydown',function(e){ 
//To get working with jQuery versions support .live 
//$(".ip").live('keydown',function(e){ 
$(document).on('keydown',".ip",function(e){ 
    var code = e.keyCode || e.which; 
    var sections = $(this).val().split('.'); 
    //Only check last section! 
    var isInt  = ((code >= 48 && code <= 57) || (code >= 96 && code <= 105)); 
    if(isInt){ 
     if(sections.length < 4){ 
      //We can add another octet 
      var val = parseInt(sections[sections.length-1]+String.fromCharCode(code)); 
      if(val > 255 || parseInt(sections[sections.length-1]) == 0){ 
       $(this).val($(this).val()+"."+String.fromCharCode(code)); 
       return false; 
      } 
      return true; 
     } else { 
      //Lets prevent string manipulations, our string is long enough 
      var val = parseInt(sections[sections.length-1]+String.fromCharCode(code)); 
      if(val > 255 || parseInt(sections[sections.length-1]) == 0){ 
       return false; 
      } 
      return true; 
     } 
    } else if(code == 8 || code == 46 || code == 9 || code == 13){ 
     return true; 
    } 
    return false 
}); 

을 사용하여 사용할 수있는 기능을 제거합니다) 나는 세계에 공헌하고 싶다

스 니펫은 de IPv6 지원이 필요하면 IPv6를 지원하거나 따로 따로 서명해야합니다. anyulled가 제안한 https://code.google.com/p/jquery-input-ip-address-control/을 참조하십시오.

복잡한 구문을 제외하고는 8 진수를 분해하고 "활성"8 진수 만 검사하며 모든 유효 주소 (0.0.0.0, 0.0.0.0/0, 요법)를 지원하므로 지혜롭게 사용하지 마십시오 무효 입력을 방지하는 것 이외의 멋진 점검을하십시오. 검사기를 찾고 있다면 IP 주소 검사기에 대한 Santiago Elvira Ramirez의 게시물을 참조하십시오.

관련 문제