I am using a swipe card to capture id and use that to store attendance into the database. I have a form with jQuery that automatically submits the form when a user enter 8 character string into the input field. I want to use the data from the swipe card to do this but when I swipe my card the output I get is ;910522804?
where it should be k1052280
.
How could I trim the data so when someone swipes their card it should get rid of ; ? and the last digit
. Any help would be greatly appreciated.
The Form and jQuery code is this
<form id="SwipeForm" action="Swiped.php" method="post">
<input id="Swipe" name="studentID" type="text" value="" />
<input type="submit" value="Submit" />
</form>
<script>
$(function () {
$('#Swipe').bind('DOMAttrModified textInput input change keyup keypress paste', function() {
var vallength = $(this).val().length;
if (vallength == 8) {
$('#SwipeForm').submit();
}
});
});
</script>
<form id="SwipeForm" action="Swiped.php" method="post">
<input id="Swipe" name="studentID" type="text" value="" />
<input type="submit" value="Submit" />
</form>
Alternative you can use the strlen function with substr to get the part of your string.
$str = ';910522804?';
$str = substr($str, 1, strlen($str) - 2);
var_dump($str);