webtest Posted October 24, 2006 Share Posted October 24, 2006 Esteemed Forum Participants and Lurkers:===========================Adobe Acrobat 5.0 - Forms: Control Custom Validate ScriptI am an absolute newbie to JS, but am an otherwise fairly experienced old hacker in many languages. I have tested in MS VBA (Visual Basic for Applications - Excel) a function to validate user entered UPC codes in an Excel Cell. I'm attempting to move this into an Adobe Acrobat Form to validate the entry in a control. I have converted quite a bit of the code, thanks to the w3schools site, but here is my first dead end ...VBA:'Remove all whitespace from beginning and end of a string' leaves string with first and last characters as printable charactersmyString = Trim(myString)JS ... ???My sincere appreciation for helping me get started. Thank you for any and all comments, suggestions, and assistance in this effort.Blessings in abundance, all the best, and ENJOY!Art . . . Carlisle, PA . . . USA Link to comment Share on other sites More sharing options...
aalbetski Posted October 24, 2006 Share Posted October 24, 2006 remove leading and trailing spaces:var yourString = " this is your string "yourString = yourString.replace(/^\s*|\s*$/g,"") Link to comment Share on other sites More sharing options...
webtest Posted October 24, 2006 Author Share Posted October 24, 2006 Thank you "aalbetski", but it isn't just spaces ... "Trim" cuts off spaces, tabs, new-lines [chr(10)], etc. ... anything that isn't a printable character ... from both the front end and the back end of the string.That makes the function very valuable, but the replacement gets a lot more complex! Link to comment Share on other sites More sharing options...
webtest Posted October 24, 2006 Author Share Posted October 24, 2006 Ahhhhh ... I see from my Quickstart Guide that the RegEx "\s" is NOT just a space, but is "same as [\f\n\r\t\v]" (Formfeed, Newline Carriage Return, Tab, Vertical Tab).I can't find a code for just a Space ??? Link to comment Share on other sites More sharing options...
webtest Posted October 24, 2006 Author Share Posted October 24, 2006 I knew it was going to come to this ... not only do I have to learn JS, but I also have to learn RegEx. Oh JOY! Link to comment Share on other sites More sharing options...
webtest Posted October 25, 2006 Author Share Posted October 25, 2006 Is there a RegEx section on this forum? Where is the best tutorial/forum for Regular Expressions coding? Link to comment Share on other sites More sharing options...
aalbetski Posted October 25, 2006 Share Posted October 25, 2006 If all you want is to do is remove spaces, then replace the \s with a space var yourString = " this is your string\n "document.write(yourString.replace(/^ *| *$/g,"")) This will retain the newline character Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now