These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Trim Function in PDF JavaScript

pogulnitin
Registered: May 21 2009
Posts: 3
Answered

Hi,
Is there any equivalent "Trim" function in PDF Javascript ?
There is a need in project wherein i need to trim a value in text fields if it contains spaces so as to check wheather user has entered values or not

sample code may go like
if ( this.getField('textName').value.trim() =="")
{
//do something
}

but didnt found any such

Please help !!!

Regards
nit

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
There isn't a specific trim function, but JavaScript does supports regular expressions, which can be used to achieve the same thing.
// This Regular Expression returns true for // an empty string, or a string composed entirely of // spaces, tabs, and/or newlinesvar rgEmpty = /^\s*$/; if(rgEmpty.test(this.getField("textName").value)){...

}

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

pogulnitin
Registered: May 21 2009
Posts: 3
Hi,
Thank you for the reply
Can you please explain 'rgempty.test' means? is it a function or something?
I tried executing this funcyion in the debugger but no idea what it exactly does

if(rgEmpty.test(this.getField("textName").value))
{
...
}


Regards
nit
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Read this artical:

http://www.acrobatusers.com/tutorials/text-matching-regular-expressions

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script