how to avoid blank spaces in field value at begining and ending

ramnuka
Kilo Contributor

my question is name field value   contains any blank spaces at beginning and ending form is not submitted.

so please tell me on submit code for that..

Thanks,

Rambabu

8 REPLIES 8

Deepa Srivastav
Kilo Sage

You can use trim function for removing extra spaces...



Re: Getting a value of a description



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


ramnuka
Kilo Contributor

hi deepa,



my requirement is field does not allows blank spaces at beginning and ending.


i done myself that field does not contains blank spaces its fine. but my requirement is field not allows blank spaces at beginning and ending.


But spaces allows between name(ex:ram chow).


stefan_ojeblom
ServiceNow Employee
ServiceNow Employee

Hello ram,



Try this regular expression and see if it helps solve your issue;


regex - trim in javascript ? what this code is doing? - Stack Overflow


Mihir Mohanta
Kilo Sage

You can write on submit client script like below.(Here I am validating short description field)



function onSubmit() {


    //Type appropriate comment here, and begin script below


    var sd = g_form.getValue('short_description');


  var last = sd.charAt(sd.length-1);


  var first = sd.charAt(0);


  //alert("1st:"+first +"//Last:"+last);


  if(first ==' '|| last == ' '){


  alert("text contains blank spaces in beginning or end");


  return false;


  }


}




Thanks,


Mihir