Disallow spaces and special characters in a field - InfoPath Dev
in

InfoPath Dev

Disallow spaces and special characters in a field

Last post 11-01-2012 08:00 AM by Hilary Stoupa. 17 replies.
Page 1 of 2 (18 items) 1 2 Next >
Sort Posts: Previous Next
  • 07-15-2009 12:19 PM

    Disallow spaces and special characters in a field

    Hello!

    I'm wondering how to disallow spaces and certain characters in a text field.  Basically I only want to allow numbers, letters and dashes.  No white space at all, and no other characters.  I'm using this field as an ID throughout the site and find spaces really mess up some of my links.  I started putting data validation on that field using the "contains" option, but then I realized that there are a lot of characters I want to prevent and I can't just check for each one by one.

    For example:  MC-001-01   is good but    MC 001 01    is bad

    I'm familiar with regular expressions (although it's been awhile) in asp pages but not sure how to put that into an infopath form.  I would like a codeless way to do this since I don't have permissions right now for code in infopath forms.

    Your suggestions are appreciated!

    Thanks!!

    Filed under:
  • 07-15-2009 12:41 PM In reply to

    Re: Disallow spaces and special characters in a field

    There may be another way, but I just tested this and it worked:

    translate(field, " ","")

    I typed in Hello Clay, and it immediately reverted to HelloClay when focus changed.  I simply put that formula as my default value, although you could also set it as a rule.

    Edit:  You did say there are other characters.  I am not sure how to ONLY allow 3 types of characters.

  • 07-15-2009 01:03 PM In reply to

    Re: Disallow spaces and special characters in a field

    While that might work for spaces, what about all the different characters i don't want?  I'm afraid of how messy it can get f I have to remove all those special characters 1 by 1.

    Just noticed your edit note.  I guess i will have to keep waiting and see if anyone has any ideas for preventing characters.  Like an & sign could really mess up a query string!  Things like that I really need to prevent to make sure this field can be used to refer to the item throughout the site with no hiccups.

  • 07-15-2009 01:58 PM In reply to

    Re: Disallow spaces and special characters in a field

    You should probably use data validation and use a regular expression to give a validation error if they include characters you won't accept. I've attached a simple sample xsn to this post that might help you. You can right click and select save as to save locally, then right click the file and open in design mode to preview. Let me know if you are still using IP 2003 -- I can post IP 2003 compatible.

    Hilary Stoupa

  • 07-15-2009 02:06 PM In reply to

    Re: Disallow spaces and special characters in a field

    Well, Clayton makes a good point. Much better to just set the expression for the characters to ALLOW, since there are only 3. Here's another copy, this time I saved as 2003 compat.

    Hilary Stoupa

  • 07-15-2009 04:57 PM In reply to

    Re: Disallow spaces and special characters in a field

    Thanks so much.  Sounds like what I was looking for.  I will try it at work tomorrow.  FYI we have 2007.

     Thanks!!

  • 07-17-2009 07:38 AM In reply to

    Re: Disallow spaces and special characters in a field

    Thanks I tried the second one out and it works great :)

  • 07-17-2009 07:48 AM In reply to

    Re: Disallow spaces and special characters in a field

    Works great for me, too.  I had no idea you could do syntax like that for a custom pattern.  Thanks for the lesson, Hilary.

  • 02-19-2010 05:17 PM In reply to

    Re: Disallow spaces and special characters in a field

    Can any one help me to validate special characters?

    I want to validate texbox which allows numbers, letters and dashes and should not allow any special characters  :"#%&*:<>?\/{|}~  and white space, actually I want to add some other special characters to this  [^~`@#$ %\*]*

    Thanks in advance

    Ravi

  • 10-08-2010 12:04 PM In reply to

    • Gaston
    • Not Ranked
    • Joined on 09-23-2010
    • Posts 5

    Re: Disallow spaces and special characters in a field

    Hi ravimca, I have the same problem, Did you solve that? Thanks.
    Filed under:
  • 02-28-2012 07:07 AM In reply to

    • JackBB
    • Not Ranked
    • Joined on 02-28-2012
    • Posts 1

    Re: Disallow spaces and special characters in a field

    Hi

    I'm using the pattern [A-Za-z0-9\-]* to allow only these characters, however I would like to allow the use of blank spaces also, I've been trying but can't seem to find the right pattern to also allow spaces in this field.

    I would like to allow values like :

    blabla bla23

    blabla 123blabla  bla 12

     

    Thanks in advance

     

    Jack

  • 04-26-2012 08:19 AM In reply to

    Re: Disallow spaces and special characters in a field

    Hilary,

    I like so much your answers and this is not the first time you help me with.

    Thank you so much, I have to create an user just to said thank you.

    Alex Morales

  • 04-26-2012 08:33 AM In reply to

    Re: Disallow spaces and special characters in a field

    Alex - you just made my day! Thanks!

    Jack - sorry I didn't see your post earlier. I'm attaching an updated sample that allows white space (the escape for that is /s).

    Hilary Stoupa

  • 06-05-2012 04:40 AM In reply to

    Re: Disallow spaces and special characters in a field

     Can you tell me how to make the text field to allow users to write only numbers?

  • 06-05-2012 08:02 AM In reply to

    Re: Disallow spaces and special characters in a field

    The easiest approach there may just be to change the data type - set it to whole number (or decimal, if that's what you need). I'm not sure you'd need a custom pattern for this? Unless your "numbers" can start with zero, or include spaces, etc?

    Hilary Stoupa

Page 1 of 2 (18 items) 1 2 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.