Jump to content

problem with a function to validate ''dots'' in an ip address


Bian

Recommended Posts

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...