Topic awaiting preservation: How do i trim "space" input into a form field before validating |
|
---|---|
Author | Thread |
Nervous Wreck (II) Inmate From: |
posted 08-18-2004 16:48
Hi guy, code: if (form.field.value.length=="" ){
|
Paranoid (IV) Mad Librarian From: Berlin (almost) |
posted 08-18-2004 17:48
Javascript doesn't have a trim function built-in, but there are many available on the web - here's the first result of a Google search for "javascript trim function": |
Nervous Wreck (II) Inmate From: London |
posted 08-18-2004 18:02
I use this, personally: code: function stringTrim(strToTrim) {
|
Nervous Wreck (II) Inmate From: |
posted 08-19-2004 10:18
"To DAN" or who might ba able to explain... code: function stringTrim(strToTrim) {
|
Nervous Wreck (II) Inmate From: London |
posted 08-19-2004 10:25
quote:
|
Obsessive-Compulsive (I) Inmate From: UK |
posted 08-19-2004 11:59
Regular expressions are an incredibly useful thing to learn because once you've picked them up, they work the same way in pretty much any scripting language. (http://www.physics.rutgers.edu/~kotliar/perltut.html#77-BasicRegularExpressions is where I originally learned them...) There's far too much to condense into a post here, but a very brief explanation of how they work in this case: |
Nervous Wreck (II) Inmate From: |
posted 08-19-2004 18:46
Thanks shingebis! your explanation was helpful and the site was usefull too. I think most programmer/Developers should get aquinted with "regexes"... |