validation - Validating a text input to use only lower cases and numbers 0 to 9 when a link is clicked -
i making simple web app reads short urls specific domain , opens short url in existing internet browser. functionality working bit confused on how move forward in adding input validations make system more self service. validate text input field not using form. want text field support small case , numbers 0 9. i've found solutions here in forum not capable of integrating offered solutions because of them use forms , programming skill beginner's level. input field uses link anchor , looks this:
<input type="text" id="keyword" placeholder="small letters only" /> <a class="btn" href="http://mysite.com" id="domain"></a>
i need add following functions in jquery script:
when link clicked, script check if character string provided in "keyword" lowercase , numbers only. if user inputs character other lowercase letters , numbers, alert message pops "invalid character detected. try again".
if no input provided when link clicked, alert message pops "provide input." .
when input valid, script below run.
thank assistance.
$(function() { $('#domain').click( function() { window.location = $(this).attr('href') + '/' + $('#keyword').val(); return false; } }); });
you can use regular expressions validation.
$(function { $('#domain').click( function() { var val = $('#keyword').val(); if (val == '') { /* popup time */ } var regexp = new regexp("[a-z0-9]+"); if (regexp.match(val)) { /* redirect */ } else { /* invalid characters */ } }) });
Comments
Post a Comment