JavaScript Custom Trim Function in DNN DynamicForm to Remove Leading/Trailing Space

There is no built-in Trim function in the javascript library implemented for DynamicForm. But you can add a custom trim function at the module definition section and use the function in field client script code. Here is the detail.

You need to add a trim function to the form’s JavaScript section first and then use the simple syntax as you want:

$(LastName) = trim($(LastName)); >>Advanced Field Options >>Client side event >>Put the above Javascript in the box for each Field. Case sensetive so use “trim” instead of “Trim”!

You can put either trim function below to the Javascript section:

>>Setup Module Configuration >>Advanced Coding Options (AJAX, jQuery, JavaScript, Initial SQL DataBind) >> Custom JavaScript File >> JavaScript File

(Add the trim function within this section and click on Update Javascript File and then click on Update Settings

You can choose one of the below trim functions:

function trim(stringToTrim) {

return stringToTrim.replace(/^\s+|\s+$/g,””);


/* */

Or this one:

function trim(s) {

var l=0;

var r=s.length -1;

while(l < s.length && s[l] == ‘ ‘)





(r > l && s[r] == ‘ ‘)




return s.substring(l, r+1);


/* */


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s