0

How can i create a custom function in jquery?

I want to use that on text inputs, to check with trim, that the user really entered some text, or just white spaces.

Takács Zoltán
  • 117
  • 3
  • 13

1 Answers1

1

You can use .trim() function.

if ($.trim($("input-selector").val()))
{
   //do Something
}
Hamed Javaheri
  • 538
  • 3
  • 13
  • He can check directly $.trim($("input-selector").val()); – Deep Jul 23 '16 at 10:47
  • You mean like this? kerdes_nev = $('#kerdes_nev').val(); if (!$.trim(kerdes_nev)) { FormErros.push("Show the error message...."); } – Takács Zoltán Jul 23 '16 at 11:00
  • @Takács Zoltán: Yes,It depends on your validation and show error message mechanism.and you can also using jquery validation plugin: https://jqueryvalidation.org/files/demo/ – Hamed Javaheri Jul 23 '16 at 11:06