Forums

Validation not working

InternEd 14 May, 2014
Hi,

I'm trying to validate a field to confirm to be a 'Full Qualified Domain Name'.

I read the FAQ and copied the code from it to an Load JS action in my form.
The Regex I found should be good to check for a FQDN.

I also copied the provided code ( validate['required','%customCheck'] ) to the Field Class box of the element.

No matter what I put in the field, the form is alway submitted. Can you tell me what I did wrong?

The code I used is:

function customCheck(el){
  if ( !el.value.test((?=^.{1,254}$)(^(?:(?!\d+.)[a-zA-Z0-9_-]{1,63}.?)+(?:[a-zA-Z]{2,})$)) ) {
    el.errors.push("Please provide a valid FQDN");
      return false;
  } else {
    return true;
  }
}
GreyHead 14 May, 2014
Hi InternEd,

The code looks OK to me.

Please post a link to the form so I can take a quick look.

Bob
InternEd 14 May, 2014
Hi Bob,

Here's the link: http://www.fotocursuswestland.nl/index.php?option=com_chronoforms&chronoform=TEST_FQDN_evaluation_license_request
GreyHead 15 May, 2014
hi InterEd,

I think that the problem is with the Regex string, specifically the ?= at the beginning and a missing ( somewhere. Please try this version
/^(.{1,254}$)(^(?:(?!\d+.)[a-zA-Z0-9_-]{1,63}.?)+(?:[a-zA-Z]{2,})$/m


Bob
InternEd 19 May, 2014
Hi Bob,

I've changed the code and counted brackets. And put in a many right-brackets as needed to get the same left as right brackets. The code now look like this:

function customCheck(el){
  if ( !el.value.test (/^(.{1,254}$)(^(?:(?!\d+.)[a-zA-Z0-9_-]{1,63}.?)+(?:[a-zA-Z]{2,})$/m))) {
    el.errors.push("Please provide a valid FQDN");
      return false;
  } else {
    return true;
  }
}


But I don't see an error when filling in a false fqdn. Could it be someting else?

Ed.
GreyHead 19 May, 2014
Hi Ed,

Here's what Regex Buddy tells me your Regex is checking for. I suspect that the first group (.{1,254}$) is still wrong - maybe the example you found wasn't in JavaScript format?

Bob

FQDN test

^(.{1,254}$)(^(?:(?!\d+.)[a-zA-Z0-9_-]{1,63}.?)+(?:[a-zA-Z]{2,})$

Options: Case sensitive; ^$ match at line breaks

Assert position at the beginning of a line (at beginning of the string or after a line break character) (line feed, line feed, line separator, paragraph separator) «^»
Match the regex below and capture its match into backreference number 1 «(.{1,254}$)»
   Match any single character that is NOT a line break character (line feed, carriage return, line separator, paragraph separator) «.{1,254}»
      Between one and 254 times, as many times as possible, giving back as needed (greedy) «{1,254}»
   Assert position at the end of a line (at the end of the string or before a line break character) (line feed, line feed, line separator, paragraph separator) «$»
Opening parenthesis without a corresponding closing parenthesis «(^(?:(?!\d+.)[a-zA-Z0-9_-]{1,63}.?)+(?:[a-zA-Z]{2,})$»
   Assert position at the beginning of a line (at beginning of the string or after a line break character) (line feed, line feed, line separator, paragraph separator) «^»
   Match the regular expression below «(?:(?!\d+.)[a-zA-Z0-9_-]{1,63}.?)+»
      Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
      Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?!\d+.)»
         Match a single character that is a “digit” (ASCII 0–9 only) «\d+»
            Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
         Match any single character that is NOT a line break character (line feed, carriage return, line separator, paragraph separator) «.»
      Match a single character present in the list below «[a-zA-Z0-9_-]{1,63}»
         Between one and 63 times, as many times as possible, giving back as needed (greedy) «{1,63}»
         A character in the range between “a” and “z” (case sensitive) «a-z»
         A character in the range between “A” and “Z” (case sensitive) «A-Z»
         A character in the range between “0” and “9” «0-9»
         The literal character “_” «_»
         The literal character “-” «-»
      Match any single character that is NOT a line break character (line feed, carriage return, line separator, paragraph separator) «.?»
         Between zero and one times, as many times as possible, giving back as needed (greedy) «?»
   Match the regular expression below «(?:[a-zA-Z]{2,})»
      Match a single character present in the list below «[a-zA-Z]{2,}»
         Between 2 and unlimited times, as many times as possible, giving back as needed (greedy) «{2,}»
         A character in the range between “a” and “z” (case sensitive) «a-z»
         A character in the range between “A” and “Z” (case sensitive) «A-Z»
   Assert position at the end of a line (at the end of the string or before a line break character) (line feed, line feed, line separator, paragraph separator) «$»

Created with RegexBuddy
InternEd 19 May, 2014

Here's what Regex Buddy tells me your Regex is checking for. I suspect that the first group (.{1,254}$) is still wrong - maybe the example you found wasn't in JavaScript format?



I didn't know there could be a difference in usable format. I'll go and check that.

Tnx!
InternEd 16 Jun, 2014
I still can't get this to work. For testing purposes I've replaced the code with this:

function customCheck(el){
  if ( !el.value.test(^[0-9]+$) ) {
    el.errors.push("only numers please");
      return false;
  } else {
    return true;
  }
}


A very simple regex, which checks for numbers. But still I can fill in anything without getting an error message.
BTW: when should the message appear? When you fill in the field? Leave the field? Or submit the form?

Does anyone have a working example of a regex test in a Chronoform so I can see what it should look like?

Tnx!
IGJ 03 Jul, 2014
Hi

I have also a problem with the validation. I have four text boxses that needs to be filled with info. I have made the fields required but the form submits even if there is no data.

What have I done wrong?

Regards
IGJ
This topic is locked and no more replies can be posted.