Specific data validation with text box - InfoPath Dev
in

InfoPath Dev

Specific data validation with text box

Last post 02-25-2014 07:39 AM by JeffVojtko. 17 replies.
Page 1 of 2 (18 items) 1 2 Next >
Sort Posts: Previous Next
  • 01-06-2010 07:58 PM

    Specific data validation with text box

     Hi guys,

     I am trying to use data validation to allow a user to enter a name field with these conditions:

    1. The name can be any length.

    2. It must only be alphabetical characters.

    3. It can have zero or more white spaces.

    4. It must not contain any any illegal characters other than the alpha + spaces.

    I have tried the simple checks but it doesn't seem to work. The pattern matching is somehow different from regular expression at least from my observation or if anyone can suggest a pattern, i have checked google and most of them don't allow spaces or multiple words separated by spaces such as 

     John  Ander Smith

     Is there anyway to do this without going into C#/VB codes?

    As this is a very common thing for name fields.

    Many thanks,

     

  • 01-06-2010 11:03 PM In reply to

    Re: Specific data validation with text box

    create an additional text box,

    on first text box put a rule to set the value of second text box to

    translate(translate(., " ", "a"), "α", "b")

    on first text box write a data validation

    if textbox2 doesnotmatch pattern \p{L}+

    this should help you

    Qazi Anis
    Technical Architect
    Bitwise Inc
  • 01-07-2010 05:01 AM In reply to

    Re: Specific data validation with text box

     Why do you need to create another text box?  (I'm a bit confused).

    I want to validate something like this:



    First name:    [ user can type anything matching the condition stated above].

    I just want to validate a simple text box :).

     I'll try your solution and see what happens.

  • 01-07-2010 05:07 AM In reply to

    Re: Specific data validation with text box

     I tried your pattern without the second text box, it seems to work ?

    I'll have to do further testing but thank you very much.

  • 01-07-2010 05:10 AM In reply to

    Re: Specific data validation with text box

     The pattern does not take into account spaces.

     However the alpha words are fine but as soon as i put in trailing and leading spaces it generates a validation error.

     

     

  • 01-07-2010 08:00 AM In reply to

    Re: Specific data validation with text box

    hi,

    well if you check properly,

    i am setting value of second text box to value of first text box - spaces and alphas

    i am validating second text box based on the validation of first text box.

    give it a shot

    Qazi Anis
    Technical Architect
    Bitwise Inc
  • 01-07-2010 08:02 AM In reply to

    Re: Specific data validation with text box

    also one thing " " this is space not a blank

    Qazi Anis
    Technical Architect
    Bitwise Inc
  • 02-06-2010 02:16 AM In reply to

    Re: Specific data validation with text box

     I also don't understand why you would suggest using a separate textbox to perform this validation.  That would give the user a confusing textbox with all the spaces converted to as.

    This pattern should work:

    [a-zA-Z]([ ]*[a-zA-Z])*

    The pattern above will approve strings that meet all of the following criteria:

    Contains one or more letters

    Contains 0 or more spaces

    Begins and ends with a letter

    Contains no characters that are not letters or spaces

    I know you didn't mention the third criterion, but I would imagine that's what you want.  If you don't mind spaces at the beginning and end but still want to require at least one letter, you can use this pattern:

    [ ]*[a-zA-Z][a-zA-Z ]*

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 11-15-2012 11:42 AM In reply to

    • Pasu
    • Not Ranked
    • Joined on 12-13-2006
    • USA
    • Posts 24

    Re: Specific data validation with text box

    I am using SaveToSharePoint qRules method to save InfoPath attachments in a SharePoint document library. When we try to attach files with illegal filename characters (\ / : * ? " < > | # { } % ~ &), the SaveToSharePoint method succeeds but cutting off all characters after the first occurence of the illegal character. That leaves the residue in tha document library, with a broken link inside Infopath. To avoid users uploading a file with illegal character, I am trying to validate the filename of an attachment, using the GetAttachmentAttribute qRules method. Is it possible to validate the result of the GetAttachmentAttribute method to check whether it contains any of the illegal characters, using a pattern?

    Thanks a lot in advance.

  • 11-15-2012 05:16 PM In reply to

    Re: Specific data validation with text box

    Yes, you should be able to do this. I think this pattern would work:

    [^\\ / : * ? " < > | # { } % ~ &]

    So, you'd run your rule for GetAttachmentAttribute, then add another rule with a condition that the qRules data source Result node matches this pattern, and you could then clear the node where they attached the file or give them a message or some such....

    Hilary Stoupa

  • 11-29-2012 09:12 AM In reply to

    • Pasu
    • Not Ranked
    • Joined on 12-13-2006
    • USA
    • Posts 24

    Re: Specific data validation with text box

    Thanks Hilary. I tried the following, but got invalid pattern error.

    Rule 

    Condition 

    Data Entry Pattern

     Invalid Pattern Error

    Any help is appreciated.

    Thanks!!

  • 11-29-2012 09:37 AM In reply to

    Re: Specific data validation with text box

    That's what I get for testing my regular expression outside of InfoPath.... I'll take a look later today & see if I can come up with something that will work for you.
    Hilary Stoupa

  • 11-29-2012 01:47 PM In reply to

    • Pasu
    • Not Ranked
    • Joined on 12-13-2006
    • USA
    • Posts 24

    Re: Specific data validation with text box

     Thanks Hilary. For now, I am using the following expression to validate the filename of an attachment. But, if there is a better way, I would like to adapt that.

    The expression... 

  • 11-29-2012 06:24 PM In reply to

    Re: Specific data validation with text box

    Well, I don't have anything that seems to do any good with custom pattern function in IP. However, I do have something you can do using qRules - what version are you using? This is using the ReplaceString command, that I think I added in v 4.2....

    You'd have to store your Result from GetAttachmentAttribute in another field - I'm just using a main data source field, but you could use a 2ds and include the dsnamesrc param:

    ReplaceString /xpathsrc=/my:myFields/my:field1 /pattern=[^\\ / : * ? " < > | # { } % ~ &]

    If the command returns anything to the Result field, you have one of the special chars listed....

    Hilary Stoupa

  • 11-30-2012 07:06 AM In reply to

    Re: Specific data validation with text box

    You could also use this condition to check whether a field contains any of the characters you're checking for:

    Field != translate(Field, '^\:*?"<>|#{}%~&', "")

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