Tagged: search function
- August 30, 2010 at 6:33 pm #565
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:
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.August 31, 2010 at 9:21 pm #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.August 31, 2010 at 9:49 pm #5418
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.August 31, 2010 at 9:52 pm #5419
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.August 31, 2010 at 11:54 pm #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.August 31, 2010 at 11:59 pm #5423
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.September 1, 2010 at 3:51 pm #5427
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.September 1, 2010 at 4:36 pm #5428
Nice, I will probably wind up using that myself sometime soon.
You must be logged in to reply to this topic.