I have a input field with number and text , i want to split only number and use it for next actions how to do ?
<input type="text" value="remain 24" name="none">
I have a input field with number and text , i want to split only number and use it for next actions how to do ?
<input type="text" value="remain 24" name="none">
html:
<input id="txtInput" type="text" value="remain 24" name="none">
Jquery :
var Number = $("#txtInput").val().split(' ')[1];
alert(Number);
Also you can use Regex.
Number = $("#txtInput").val().match(/\d+/);
<input type="text" value="remain 24" name="none">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var yourTxt = $('input').val();
var number = yourTxt.replace(/[^0-9]/g, '');
$('input').val(number);
});
</script>
you can use regex to get only numbers from the string.
First get the value from that input, and it will be a string
var inputVal = $('input').val();
var extractedNum = inputVal.match(/\d+/)[0];