how to check if a field contains backslash using client script

sahitya1
Tera Contributor

how to check if a field contains backslash using client script

5 REPLIES 5

ramireddy
Mega Guru

In Javascript, escape character is backslash. So, you need to use 2 black slashes in this case. Then, you can use indexOf javascript function to check whether value has blackslash or not.



var fieldvalue = g_form.getValue('fieldname');


if(fieldValue.indexOf('\\') >= 0)


      alert("Field value has black slash.")


It is working
thank you
but can we do it using regex?


here it is using regex..



Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


Thanks,
Deepa



var pattern=/\\/;
alert(pattern.test(newValue));
 



if(pattern.test(newValue) )



{
          alert('Backslash presnt);


          g_form.setValue('u_urfieldname', '');


  }


That's great. Check this, if you want to use reg. ex



var fieldvalue = g_form.getValue('fieldname');  


var reg=/\b\\/g;


if(fieldvalue.match(reg))  


    alert("Field value has black slash.")