0

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?

Greg Ostry
  • 1,161
  • 5
  • 27
  • 52

2 Answers2

1

You can simply use .replace(/\s+/g,'') `

$("input[name='myLabel']").on('keyup', renderInput);
function renderInput() {
  input = $(this).val();
  $(this).val(input.replace(/\s+/g,''));
}

`

0

Use :

input.match(/\s+/g) 

Or :

Var reg = new regex("\\s", "g")