ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Is it possible to disallow spaces in a form field?

October 30, 2007 9:49am

Subscribe [1]
  • #1 / Oct 30, 2007 9:49am

    Mark Bowen

    12637 posts

    Hi there,

    I was just wondering if anyone had any ideas as to how I could achieve something?

    At the moment I have an SAEF working and it is using the File extension to allow me to upload a file along with the weblog entry.
    The problem I have is that the File extension doesn’t get rid of spaces in file names so I am having problems using the URL that is placed into the weblog. I tried using Extract URL on it but this won’t work.

    What I would therefore like to do as I don’t want people to upload any files with spaces in anyway as to me that is a big no no is use some javascript validation on the field and not allow the form to be sent if that field has any spaces contained in it.

    I took a look at the Live Validation Javascript available on the web which I am actually using on the form anyway but don’t know if it is possible to write a regular expression to check for this sort of thing.

    My problem here is two-fold really. I am pretty sure that you can use regular expressions to achieve this kind of thing as the Live Validation documents say you can but then the second part is that I have absolutely no knowledge of how to write regular expressions. I have read pages and pages about them but just cannot get my head around them at all.

    So to my question which is simply, can a regular expression be written to check that there aren’t any spaces in a certain field in a form on an SAEF and will this work with the Live Validation script?

    Sorry for all the questions but any help with this would be massively appreciated.

    Best wishes,

    Mark

  • #2 / Oct 30, 2007 4:22pm

    Mark Bowen

    12637 posts

    Found it!!

    Should have done more of a search on the web first and could have answered my own question!! 😊

    Unfortunately I can’t seem to get this to work on an input field as it isn’t really a field of sorts. Oh well will look at doing something else.

    Just in case anyone wants a regular expression in the future to check against spaces then you can use one of the two shown below. Thought it might help someone out somewhere along the line.

    Version 1:
    /^\S+$/i
    
    Version 2:
    /^[a-zA-Z]+$/i

    Best wishes,

    Mark

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases