How can we set validation for no space in the text field.

  • Profile Image
    Asked on December 11, 2011 at 06:26 AM

    I have a field where I would like the user to enter only alphanumeric text without any space. How do I do that. Can you please let me know how to achieve that

  • Profile Image
    Answered on December 11, 2011 at 09:47 AM

    Hi NeetaKapadia,


    Here's how you can set the validation for your text field:

    1. Open your form 

    2. Click on the "user" text field

    3. Click on "Properties: Name" on the top menu

    4. Click on the "Validation" icon and set to "AlphaNumeric"


    Hope this will help you. Thank you for using JotForm!



  • Profile Image
    Answered on December 11, 2011 at 09:58 AM



    Unfortunately, we don't have direct tool for no space validation but If you like, you can try this workaround. In order to achieve that you need to download your form's full source code, here's a guide for that: 

    After downloading your form's source code, open the html file (can be found on the downloaded form files).

    On the html code, under <head> tag please add the code below:


    <script type="text/javascript">

    function nospaces(t){


    alert('Sorry, you are not allowed to enter any spaces');






    After that, add this code onkeyup="nospaces(this)" inside the Text Box code. (This should be the Text Box where you don't want to allow any spaces. Please see sample structure below.)

    <input type="text" name ="textbox" id="textbox" onkeyup="nospaces(this)">

    Here's sample demo: Click HERE

    Let me know if you have further questions. Thanks.


  • Profile Image
    Answered on October 14, 2012 at 07:01 AM

    Nice code. Thanks idarktech

  • Profile Image
    Answered on October 14, 2012 at 07:20 AM

    In behalf of my colleague, we're glad to be of help, if you have further questions feel free to contact us.

    Thanks for using JotForm!

  • Profile Image
    Anup Shaji
    Answered on January 11, 2013 at 06:34 AM

    Thankx idarktech... this was helpful....

  • Profile Image
    aarthy d
    Answered on September 18, 2013 at 01:27 AM


  • Profile Image
    Answered on September 18, 2013 at 01:30 AM

    thank uu.........

  • Profile Image
    Answered on September 18, 2013 at 08:14 AM

    ThankU man..............


  • Profile Image
    Answered on October 01, 2014 at 02:27 AM

    thank you..

  • Profile Image
    Answered on February 11, 2015 at 12:59 PM

    what is the meaning of symbols in code

    (if(t.value.match(/\s/g)))      t.value=t.value.replace(/\s/g,'')

    please give the answer 

    thank you

  • Profile Image
    Answered on February 11, 2015 at 02:04 PM

    Hi Siva,

    The code above is called regex code that is used to find and if found remove space characters from the text.

    Now, as this is a very old thread, if you have any further questions in regards to this, please let us know by opening your own thread.

    Thank you.

  • Profile Image
    Answered on July 21, 2015 at 05:20 AM


  • Profile Image
    Yasir Ihsan 
    Answered on August 18, 2015 at 04:11 AM


    I was searching for the long time no one put executable code. Every person is misguiding. Thanks for the code it is 100% working and running fine on my page.

  • Profile Image
    Answered on January 21, 2016 at 02:21 AM

    Thanks Bro..Awesome It Is!

  • Profile Image
    Answered on March 28, 2016 at 07:47 AM

    Thankyou it was helpful

  • Profile Image
    Answered on August 18, 2016 at 01:38 AM


  • Profile Image
    Answered on November 13, 2016 at 01:08 AM

    Thanks It's worked well

  • Profile Image
    Answered on January 04, 2017 at 11:15 PM

    my validation needs some space below the text field. the validation text is postioning
  • Profile Image
    Answered on January 05, 2017 at 02:11 AM


    I have moved your question to separate thread and we will provide you an answer there shortly.