Hi everybody. After working on this for a bit, I figured it out for myself. The problem was that in the variable definition, I was using <var-jsType>regexp</var-jsType>. This is wrong - the proper way to do it is <var-jstype>regexp</var-jstype>.
Hopefully this will help somebody else out at some point. Matt Bathje ----- Original Message ----- From: "Matt Bathje" <[EMAIL PROTECTED]> To: "strutslist" <[EMAIL PROTECTED]> Sent: Wednesday, January 28, 2004 12:44 PM Subject: custom javascript validation > Hi all. > > I am doing some custom validations, and the server side of them is working > well. The problem is that in my custom javascript, I cannot get a variable I > have defined as a regular expression to work. The javascript always pulls > out the backslashes (\) from the regexp. If I put in the regular expression > with double backslashes, it works for javascript, but breaks in the java > end. Plus I would really like to not have to use "nonstandard" regexps. > > I am using the mask validator as my guide, and it seems the big difference > is when the "validation function" is created, in mask the regexp variables > get created as regular expressions, where as in my validator they get > created as strings. For example, here is the created mask function: > > function mask () { > this.a0 = new Array("phone", "Phone Number is invalid.", new Function > ("varName", > this.mask=/^(^\\([2-9]\\d{2}\\)\\s*\\d{3}-\\d{4}$)|(^[2-9]\\d{2}-\\d{3}-\\d{ > 4}$)$/; return this[varName];")); > } > > and here is my function: > function countryMask () { > this.a0 = new Array("postalCode", "Postal Code is invalid.", new Function > ("varName", > "this.CAN='^([ABCEGHJKLMNPRSTVXYabceghjklmnprstvxy]\\d[A-Za-z]\\s*\\d[A-Za-z > ]\\d)$'; this.otherField='countryID'; > this.USA='^(^\\d{5}$)|(^\\d{5}-\\d{4}$)$'; return this[varName];")); > } > > > See how in the mask function this.mask is set to a regular expression - no > quotes around it? But in my function, this.USA and this.CAN are both created > as strings with quotes around them (and no regexp demarkers (/)) > > Also, notice that at this point this.USA and this.CAN both have the slashes > in them as needed. But, in my validation script when I do var pattern = > oCountryMask[x][2](CAN);, pattern does not contain the slashes. > > What I am looking for is either a way to call oCountryMask[x][2](CAN) and > have it not strip the slashes, OR (and even better) have the var treated as > a regexp like the mask variable is. > > Obviously the "mask" variable for a mask validation is a special variable > that gets treated as a regexp - but is there any way to set the "javascript > type" of the variable in my validation? > > I was poking around in the validator javadocs and found > <var-jsType>regexp</var-jsType> looks like it may do something, but it > unfortunatley does not solve my problem. I'm wondering if maybe it isn't > implemented yet or something? > > I have really been able to find anybody else mentioning similar problems. :( > > Any help to get this working would be greatly appreciated!!! > > Thanks, > Matt Bathje > > ps - anybody have any knowledge about these three questions that were never > answered? > http://nagoya.apache.org/eyebrowse/[EMAIL PROTECTED]&msgId=1327188 > http://nagoya.apache.org/eyebrowse/[EMAIL PROTECTED]&msgId=1328405 > http://nagoya.apache.org/eyebrowse/[EMAIL PROTECTED]&msgId=1328406 > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]