Akshay N Shaju Akshay N Shaju - 1 month ago 17
HTML Question

checking nth digit of a number(12digit number)

i'm working on a project, that users enter their 12 digit registration number (ex : 201610132025 ) 2016(year),10(month), 132(target), 025(user identifier)

while they entering on html input field, i need to check their target, month, college, user identifier.
for that how can i separate or divide this reg no in background in java and validate.

<input type="text" id="reg_no" name="reg_no" placeholder="register no" onblur="myFunction()">

<input type="text" id="year" name="year">
<input type="text" id="month" name="month">
<input type="text" id="target" name="target">
<input type="text" id="u_id" name="u_id">


for the above example,'OnBlur' it should replace the value of following

<input type="text" id="year" name="year"> //2016
<input type="text" id="month" name="month"> //10
<input type="text" id="target" name="target"> //132
<input type="text" id="u_id" name="u_id"> //025

Answer

You don't required to hit any webservice to do such thing. Instead you can set required fields' value using Javascript like below :

function myFunc(regNo){
    $('#year').val(regNo.substr(0,4));
    $('#month').val(regNo.substr(4,2));
    $('#target').val(regNo.substr(6,3));
    $('#target').val(regNo.substr(9));
}