The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › CSS › Javacript URL validation
Hi mi currently have the following code that checks if there is the “http://” in front of it and if there is none it adds it
$('.urlinput').keypress(function(e) { if (e.keyCode == 13) { var value = $(this).val() var ini = $(this).val().substring(0, 4); if (ini !== 'http') { cur_val = value value.val('http://' + cur_val + '/'); } } });
My question is how do i integrate a validation system?
Try this:
$('.urlinput').keypress(function(e) { // use e.which here, it's been normalized across browsers by jQuery if (e.which === 13) { var value = $(this).val(); var ini = $(this).val().substring(0, 4); if (ini !== 'http') { value = 'http://' + value + '/'; $(this).val(value); } // *** ADD your URL validation here; check "value" *** } });