JQuery有一個好的IP Mask插件嗎?我試過Masked Input Plugin,但它沒有少於12位的IP地址。然後我嘗試了meioMask,這不能用少於12位的數字。有什麼建議麼?我需要一個JQuery IP Mask插件
回答
從蒙面輸入插件的工作實例 -
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的水印 - http://code.google.com/p/jquery-watermark/
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;
}
}
但是,這是一個較舊的職位的人誰希望有一個簡單的方法來處理多個輸入,而不使用膨脹插件,或者不必擔心文檔或方法,這裏有一個簡單的類選擇器方法,它可以完成所有這些。它只有IPv4,但它聽起來像你的需求非常簡單。
//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」,它會自動完成剩下的事情:d該版本支持CIDR標記(如:192.168.1.1/16)只允許有效的地址輸入,刪除CIDR功能,您可以使用使用下面的代碼片段(未測試)
//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
});
我在這裏提供的代碼有兩個目的1)這是我認爲需要解決的問題,2 )我希望對世界做出貢獻
這段代碼不是de簽署拆分,也不支持IPv6,如果您需要IPv6支持,請參閱已提示的https://code.google.com/p/jquery-input-ip-address-control/。
但是除了複雜的語法之外,它將八位字節分開,只檢查「活動」字節,它支持任何VALID地址(0.0.0.0,0.0.0.0/0等),所以明智地使用它不會除防止無效輸入之外,不要做任何奇怪的檢查。如果您正在尋找一個檢查器,請參閱Santiago Elvira Ramirez關於IP地址驗證器的文章。
- 1. Heroku和ip mask
- 2. 我需要一個IP地址嗎?
- 3. 我需要另一個用於Draggable的JQuery插件嗎?
- 4. jQuery插件,需要一個交叉淡入插件
- 5. 我需要使用Struts2的,jQuery插件
- 6. 我需要Jquery裁剪圖片插件
- 7. 哪個eclipse插件我需要這個?
- 8. 需要輸入jQuery插件
- 9. 需要JQuery圖形插件
- 10. jQuery插件:需要反饋
- 11. 是否有一個不需要jQuery的jQuery排序插件?
- 12. 科爾多瓦需要一個插件
- 13. 我需要一個jQuery效果
- 14. 需要一個修改CSS的jQuery插件
- 15. 需要一個jQuery插件類似於eXtplorer的
- 16. 需要一個IP位置查找
- 17. 我的第一個jQuery插件:需要提示做得更好+超時問題
- 18. 我需要一個方便的jQuery工具(插件)來處理地圖
- 19. 我只需要一個WSDL,我也需要一個XSD?
- 20. 我需要一個Firefox插件還是擴展?
- 21. WPF GUI插件設計。我需要一個小小的反饋
- 22. 需要一個jQuery代碼:
- 23. 需要一個「有」 jQuery中
- 24. 我們需要一個靜態IP來使用HTML5 Websockets嗎?
- 25. jQuery插件需要調用本身
- 26. 需要顯示Toastr通知jQuery插件
- 27. 需要更新插件使用jQuery 1.4.3
- 28. 需要jQuery的xpath選擇器插件
- 29. 需要帶有Webpack的jQuery插件
- 30. jQuery Image Mask
你是什麼意思「不少於12位數字」?你能告訴我一些例子嗎? – Kai 2010-07-06 07:41:59
10.10.10.10 <12位數字 – HyderA 2010-07-19 05:48:32
IPv6更多我猜是這個問題,所以它不適用於IPv4?另外請張貼一些例子/代碼來幫助你做什麼,你不能得到一個合理的答案與一個合理的問題。所以我只能說42. – Sphvn 2010-07-19 05:53:08