Remove any initial spaces from field - scripts?

New Here ,
Sep 13, 2022 Sep 13, 2022

Copy link to clipboard

Copied

Is there a way to remove any initial spaces for a text field. So if user enters: [ Bill] it formats it to: [Bill].

 

This is for a validation check so the user cannot just enter spaces and is required to enter a name. Maybe a way to check for letters as well. 

 

if (getField("step1.namefield").valueAsString === ""){

( As spaces pass check for this) 

 

TOPICS
Create PDFs , JavaScript , PDF forms , Standards and accessibility

Views

29

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 15, 2022 Sep 15, 2022

Copy link to clipboard

Copied

LATEST

You should use the "trim()" method: https://www.w3schools.com/jsref/jsref_trim_string.asp

Be careful, PDF-JavaScript (ECMAScript) does not support "let", use "var" instead.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

Make content for your business needs with Adobe Express.

Get started easily with free templates: