Reputation: 1231
how do i detect a whitespace "space" in a string.
My string are somtehing like this 0651160403XL 00CBD012
my code:
<input type="text" name="myLabel"><br>
<span></span>
<script>
$("input[name='myLabel']").on('keyup', renderInput);
function renderInput() {
input = $(this).val();
if(input.match("/\s+/g"))
//trim the input to 0651160403XL
});
</script>
but my code is not working. How can i escape the slash in match function?
Upvotes: 0
Views: 102
Reputation: 183
Use :
input.match(/\s+/g)
Or :
Var reg = new regex("\\s", "g")
Upvotes: 0
Reputation: 404
You can simply use .replace(/\s+/g,'')
`
$("input[name='myLabel']").on('keyup', renderInput);
function renderInput() {
input = $(this).val();
$(this).val(input.replace(/\s+/g,''));
}
`
Upvotes: 1