Skip to Content Skip to Menu

[SOLVED] Escape character for regex validation

  • sabroso
  • sabroso
  • OFFLINE
  • Posts: 29
  • Thanks: 5
  • Karma: 1
9 years 5 months ago - 9 years 5 months ago #264186 by sabroso
Hi there,

How can I escape a forward slash in the custom regex validation for text fields?

Back slash doesn't work and it is considered as a character.I have also tried double back slash with no luck. Tried to use different string delimiters {} ## in order to use the forward slash as a character with no more luck.

I see a very odd behaviour where if I type as regex
Code:
/https:\/\/www.facebook.com/

the string that gives a match is:
Code:
http:\/\/www.facebook.com

hence why I said that the backslash was being considered as a character. I didn't escape the dots because I was seeing the same behaviour from the back slash and I realised I was able to achieve a match with no escaping.

Something odd is going on in CB since I have been trying regex validation for a while with expressions that work and match the expected strings in reliable online regex simulators but they don't work in CB.

But I'd be happy if I can escape or match the forward slashes in any way since I seem to be able to match the rest after throwing the regex book out the window and doing fair amount of trial and error

thanks
Last edit: 9 years 5 months ago by krileon.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48478
  • Thanks: 8281
  • Karma: 1443
9 years 5 months ago - 9 years 5 months ago #264199 by krileon
Replied by krileon on topic Escape character for regex validation
You need to supply a full valid REGEXP. Using a REGEXP builder program helps a lot with this. For example I have been using RegexBuddy for years now. The below should work fine.

HTTPS or HTTP
Code:
%https?://www\.facebook\.com%

HTTPS only
Code:
%https://www\.facebook\.com%

HTTP only
Code:
%http://www\.facebook\.com%

The delimiter can be whatever is needed. In this case % is used as the standard / is needed in the strict. You could just escape / of course, but it doesn't really matter.


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.
Last edit: 9 years 5 months ago by krileon.

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

  • sabroso
  • sabroso
  • OFFLINE
  • Posts: 29
  • Thanks: 5
  • Karma: 1
9 years 5 months ago #264205 by sabroso
Replied by sabroso on topic Escape character for regex validation
Hi Kyle,

Thank you for your fast response.

Unfortunately the examples you provided don't seem to work in my installation (Joomla 3.4.1 and CB 2.0.8).

As soon as I change the delimiters, using %,#, or {, there is no validation going on. CB will take any string.

Validation only seems to get enabled by using standard forward slash delimiters. Which then forces to use escaping for including forward slashes in the strict.

And as per my previous post either escaping does no work or I haven't found the right way of escaping characters in CB. I have tried back slash, double backslash, and they don't work as escaping character.

did you test your validations on a CB text field?

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48478
  • Thanks: 8281
  • Karma: 1443
9 years 5 months ago #264206 by krileon
Replied by krileon on topic Escape character for regex validation
There's 2 forms of validation. Browser (done via jQuery) and server side (done via PHP). Which validation is failing? Looks like there might be some strict validation on the regexp it self that's being applied. The below is with / delimiter.

Code:
/https?:\/\/www\.facebook\.com/


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.

  • sabroso
  • sabroso
  • OFFLINE
  • Posts: 29
  • Thanks: 5
  • Karma: 1
9 years 5 months ago #264213 by sabroso
Replied by sabroso on topic Escape character for regex validation
It was the jQuery validation. It was a browser problem, updating Firefox fixed the issue. I should have tried with a different browser, apologies. Thanks a lot for your help!
The following user(s) said Thank You: krileon

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

Moderators: beatnantkrileon
Powered by Kunena Forum