Bian Posted February 25, 2015 Share Posted February 25, 2015 Hello everyone, I need to build a program that validates an ip address in a textbox, but I need a function to locate the position of an dot to see if it is necessary to add a new dot in the chain or not, I would really appreciate it if you can help me, thank you everyone, greetings . Link to comment Share on other sites More sharing options...
thescientist Posted February 25, 2015 Share Posted February 25, 2015 what do you have so far? The issue would knowing when to insert a dot, since any value could be 1, 2 or 3 characters. Link to comment Share on other sites More sharing options...
Bian Posted February 25, 2015 Author Share Posted February 25, 2015 This is what I have Link to comment Share on other sites More sharing options...
thescientist Posted February 25, 2015 Share Posted February 25, 2015 please provide code in your post. It's hard to even see that. Link to comment Share on other sites More sharing options...
Bian Posted February 25, 2015 Author Share Posted February 25, 2015 Yes, sorry, this is the code: cKey = 0; cDots=0; cCipher=0; //function cDots() this is the function idk how to do it { cDots=0; //cDots++; //added } $(document).ready(function(){ //event page full charged $('#txtfecha').keyup(function( event ) { $('#r1').html(event.which.toString()); key = event.which; ans = !(( key >= 48 && key <= 57) || key == 8 || key == 13 || key == 190 ); txtfecha = $('#txtfecha').val(); //save the chain of the textbox if (ans){ $('#r2').html(txtfecha[txtfecha.length-1]); $('#txtfecha').val(txtfecha.substring(0,txtfecha.length-cKey)); alert('It only accepts numbers under 256'); cKey = 0; } //////////////////////////////////// if(txtfecha.length == 3 || txtfecha.length == 7 || txtfecha.length == 11) { $('#txtfecha').val(txtfecha+'.'); } //////////////////////////////////// if(txtfecha.length >= 15){ $('#txtfecha').val(txtfecha.substring(0,15)); } }); $('#txtfecha').keydown(function( event ) { key = event.which; ans = !(( key >= 48 && key <= 57) || key == 8 || key == 13 || key == 190); if (ans){ cKey++; $('#r2').html(cKey.toString()); } }); /*$('#txtfecha').keyup(function( event ) { $('#r2').html(event.which.toString()); }); $('#txtfecha').keypress(function( event ) { $('#r3').html(event.which.toString()); });*/ }); Link to comment Share on other sites More sharing options...
justsomeguy Posted February 26, 2015 Share Posted February 26, 2015 I don't think you understand the problem. If someone enters this:111111111How do you know if it's this:1.11.111.111or this:11.11.11.111or this:111.11.1.111etc. How are you supposed to figure out where the dots go? The computer doesn't know what someone meant. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now