Last active
September 6, 2016 06:51
-
-
Save alpertuna/0bc545a751f60c5e02a0ad53f39c8c9e to your computer and use it in GitHub Desktop.
Regex for Step by Step Ip Check
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/^((1?\d?\d|25[0-5]?|2[0-4]?\d?)(\.((1?\d?\d|25[0-5]?|2[0-4]?\d?)(\.((1?\d?\d|25[0-5]?|2[0-4]?\d?)(\.(1?\d?\d|25[0-5]?|2[0-4]?\d?)?)?)?)?)?)?)?$/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/^(([\da-fA-F]{1,4}(:([\da-fA-F]{1,4}(:([\da-fA-F]{1,4}(:([\da-fA-F]{1,4}(:([\da-fA-F]{1,4}(:([\da-fA-F]{1,4}(:([\da-fA-F]{1,4}(:([\da-fA-F]{0,4})?)?)?)?)?)?)?)?)?)?)?)?)?)?)|[\da-fA-F]{0,4}:(:[\da-fA-F]{0,4})?)?$/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/^(([\da-fA-F]{1,4}(:([\da-fA-F]{1,4}(:([\da-fA-F]{1,4}(:([\da-fA-F]{1,4}(:([\da-fA-F]{1,4}(:([\da-fA-F]{1,4}(:([\da-fA-F]{1,4}(:([\da-fA-F]{1,4}(\/(\d\d?|1[01]\d|12[0-8])?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)?)|[\da-fA-F]{0,4}:(:[\da-fA-F]{0,4})?(\/(\d\d?|1[01]\d|12[0-8])?)?)?$/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
^([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(\/([0-2][0-9]|3[0-2]))?$ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/^((1?\d?\d|25[0-5]?|2[0-4]?\d?)(\.((1?\d?\d|25[0-5]?|2[0-4]?\d?)(\.((1?\d?\d|25[0-5]?|2[0-4]?\d?)(\.((1?\d?\d|25[0-5]?|2[0-4]?\d?)(\/([12]?\d|3[12])?)?)?)?)?)?)?)?)?$/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var prevValue = ''; | |
function onKeyUp(e){ | |
var regex = /^((1?\d?\d|25[0-5]?|2[0-4]?\d?)(\.((1?\d?\d|25[0-5]?|2[0-4]?\d?)(\.((1?\d?\d|25[0-5]?|2[0-4]?\d?)(\.((1?\d?\d|25[0-5]?|2[0-4]?\d?)(\/([12]?\d|3[12])?)?)?)?)?)?)?)?)?$/; | |
if(!regex.test(e.target.value)) | |
e.target.value = prevValue; | |
else prevValue = e.target.value; | |
} | |
</script> | |
<input type="text" onkeyup="onKeyUp(event)" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment