How does the pattern work in the Search function?

Home Forum General How does the pattern work in the Search function?

This topic contains 7 replies, has 0 voices, and was last updated by  pmeidinger 8 years, 3 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #565

    pmeidinger
    Participant

    I want to be sure the user doesn’t use a PO Box as their physical address in a Text Input field. I’d like to use the Search funtion but am not sure how the pattern matching works. I need to check for the following, ignoring case:

    PO Box

    P O Box

    P.O. Box

    P.O Box

    Can the Search function catch all of these, and if so, what would the pattern be? I’m not familiar with regular expressions, if that’s what it’s using.

    #5417

    The Search function searches for the specified pattern within the text field and returns the position of pattern. If there is no matching pattern, -1 is returned. Flags can be used to provide more control and may be chained together if needed, as in ‘gis’.

    g: Replaces all occurrences of pattern rather than just the first one.

    i: The function is executed without case sensitivity.

    s: Within the pattern or replace text parameters, the dot ‘.’ character matches new-line characters.

    m: The caret (^) character and dollar sign ($) match before and after new-line characters. (This modifier corresponds to the multiline property of the RegExp instance.)

    x: White space characters are ignored in the pattern so that you can write more readable constructors.

    If you are searching for all the separate options, you will have to have a different search function for each possible combinations.

    #5418

    pmeidinger
    Participant

    Thanks, Dennis, but I already saw that in the documentation and it doesn’t answer my question. I need to know how to use the Pattern parameter of the Search function. Here’s my behavior that’s using the Search function to check for a PO Box: http://imgur.com/xyTq9.png.

    If I type “PO Box” into Text Input 4 and click the button that runs this behavior, I get no message. If I type “asdf” and click the button, I get the message. So I’m not understanding how the Pattern parameter of the Search function is supposed to be used to match what I’m looking for.

    #5419

    pmeidinger
    Participant

    Also, the Index Of function is working as I expected. But I thought Search could use a pattern so I could cover all (or most) occurrences of what I’m looking for in one shot, rather than having one Index Of for each string I’m looking for.

    #5422

    The documentation on the Search Function is incorrect. I apologize for the misguidance. The search function will simply return a true or false. I ran a test using your scenario. I used a hidden field into which I returned the value (true or false). Then I created a simple branch behavior that says if the value in the hidden field is true, then show a message and delete the value in the text input field. If it is not, then do nothing. *I used the flag “i” in the function to ignore the case of the letters.* Do not use the “g” flag.

    I would use search rather than Index of because you only need to find one occurrence of “PO Box” to cause a problem.

    #5423

    pmeidinger
    Participant

    Thanks, Dennis. I was wondering why Search wasn’t behaving as I expected. I’m still wondering about the pattern part, though. I’d love do be able to have it look for a pattern like (and I’m just making this up) “P[ .]O[ .] Box”, that would match on “PO Box”, “P O Box” and “P.O. Box” all at once. If it can’t do that, I’ll just make make separate checks for each possible string. Thanks again.

    #5427

    pmeidinger
    Participant

    I looked into regular expressions a bit (my first time) and came up with a pattern that works for me: P[ .]*O[.]* Box. It may not be the best, but it seems to be getting the job done. I guess I was fairly close in my previous post.

    #5428

    Nice, I will probably wind up using that myself sometime soon.

    Thank you

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.