Skip to Content Skip to Menu

trying to get the regex to work in my fields

  • bucknla
  • bucknla
  • OFFLINE
  • Posts: 26
  • Thanks: 0
  • Karma: 0
10 years 2 months ago #248151 by bucknla
I read the recommended articles you provided for understanding and creating regex but the fact remains that when i plugin a regex in my field properties it doesn't work.

Can you give me a few standard regex strings for username field? I'm sure you guys have lists of these and would at least give me ones thats are supposed to work and help me find out why mine are not. I see other posts for some of the same question with no real answers other than telling us to read the bible of regex. Why do i need to read everything on regex just to use a couple of features in community builder?

How about teaching by example instead of sending us somewhere else? More sample documents. Examples of using them. You make mention of them but you don't give even the most common as examples. If they aren't working say so instead of us having to do this by trial and error. You are the source and this is where I'm supposed to find out how to do something. I feel when I ask a question the mood here is not to help me make my site better and how to use a feature.

You have all these features that mean nothing if no one knows how to use them. I feel like you are trying to sell me a new car with blue tooth but when I ask how it works you make me read everything there is to know about blue tooth. I just want to know how to use it with your car. If you don't want to talk to members then at least have hundreds of documents we can read with examples from you. Regex examples are either gonna work or not so whom better to get them from than you?

This is one of those topics you guys could save many of you members a great deal of time and effort by including even for download 10 of the most common regex strings for fields like username and password or zip code. More examples less forum work the way i see it. Back on topic. asking for a few working examples of regex. That's it. Thanks.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48479
  • Thanks: 8282
  • Karma: 1443
10 years 2 months ago #248187 by krileon
Replied by krileon on topic trying to get the regex to work in my fields
You need to know what you're wanting to match for there to be regex for it. If there's a certain username format you want you need to provide it so regex can be customized for it. There are a few regex examples directly in the validation dropdown as well as all over the forums, but without knowing what you're wanting to match we can't possibly know what regex you need.

As there are multiple great resources available on the web for learning regex it seams redundant for us to document it as well. It'd be like asking us to document PHP or JS for example as regex is a language. The below is some great resources for regex usage.

Tutorials: www.regular-expressions.info/tutorial.html
Examples: www.regular-expressions.info/examples.html
Testing: regex101.com/

In addition to the above there are some excellent commercial programs that make writing regex pretty straight forward. RegexBuddy and RegexMagic both stand out, but personally I use RegexBuddy. I believe there's some free alternatives as well like Expresso found below.

www.ultrapico.com/Expresso.htm

There's also the below, which helps construct regex from a string. You basically select what parts of the string you want it to match and it can help provide regex to meet your match needs.

txt2re.com/

Since I don't know what you're trying to match the below are the regex provided by the validation dropdown.

Single word:
/^[a-z]*$/i

Multiple words with spaces:
/^([a-z]+ *)*$/i

Single a-z,A-Z,0-9,_ word:
/^[a-z]+[a-z0-9_]*$/i

At least 6 chars, 1 a-z, 1 A-Z, 1 0-9, 1 special:
/^(?=.*\d)(?=.*(\W|_))(?=.*[a-z])(?=.*[A-Z]).{6,255}$/

The following are some additional regex examples. Again, since I don't know what you're trying to match these may or may not be of any help.

The input must contain at least one upper case letter, one lower case letter, one digit, and must be at least 6 characters:
/\A(?=\S*?[A-Z])(?=\S*?[a-z])(?=\S*?[0-9])\S{6,}\z/

The word must contain at least one letter and at least one digit:
/\b[a-z]*(?>[a-z][0-9]+|[0-9]+[a-z])[a-z0-9]*\b/

Can only contain letters, digits, underscore, hyphen, and it must be at least 3 characters:
/^[a-z0-9_-]{3,}$/i

ZIP code (US):
/\b[0-9]{5}(?:-[0-9]{4})?\b/

Simple email address:
/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$/i


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

  • bucknla
  • bucknla
  • OFFLINE
  • Posts: 26
  • Thanks: 0
  • Karma: 0
10 years 2 months ago #248194 by bucknla
Replied by bucknla on topic trying to get the regex to work in my fields
B) B) B) Above all else let me say thank you this is exactly what i was looking for. couple examples to make sure the strings are correct. When reading the reg ex manual there were some differences in scripting languages with regards to regex and it wasn't clear do i follow Perl, PhP, JavaScript when doing my regex strings. I wasn't sure about one of your choices in community builder under the custom it says Perl strings and I don't know if I should look under Perl or PHP or JavaScript. The few examples that are in the drop down list none of mine work. I've changed to each and it made no difference as to what i could type in when I registered an new account to test. My biggest issue is limiting what can be used by my members for username to A-Z, a-z 0-9 no spaces no period but can use the hyphen or an underscore. Now to make sure I'm doing this right I choose custom perl regular expression and enter my own regex string. Is that correct?
Now that i have some strings you guys have used there should be no question if they are correct and gives me a measure to see why my attempts did not. Once again you've gone over and beyond what I was expecting from you and would like to say thank you again.
Sincerely,
D Cannon (bucknla)

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48479
  • Thanks: 8282
  • Karma: 1443
10 years 2 months ago #248225 by krileon
Replied by krileon on topic trying to get the regex to work in my fields

When reading the reg ex manual there were some differences in scripting languages with regards to regex and it wasn't clear do i follow Perl, PhP, JavaScript when doing my regex strings. I wasn't sure about one of your choices in community builder under the custom it says Perl strings and I don't know if I should look under Perl or PHP or JavaScript.

You use the minimum language you need to match in. The major limitations are shortcut features, which most of the time aren't used. In the case of field validation if you want in browser validation (currently bugged) you'll want your REGEX to be JS compatible.

The few examples that are in the drop down list none of mine work. I've changed to each and it made no difference as to what i could type in when I registered an new account to test.

That's because browser side validation is broken. When you submit the form it'll do PHP side. Browser side is fixed in CB 2.0 and functions quite a bit better now.

My biggest issue is limiting what can be used by my members for username to A-Z, a-z 0-9 no spaces no period but can use the hyphen or an underscore. Now to make sure I'm doing this right I choose custom perl regular expression and enter my own regex string. Is that correct?

Yes, the below should do what you're wanting.

/^[a-zA-Z0-9-_]+$/


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum