PDA

View Full Version : Javascript RegExp


lizac
05-18-2004, 09:40 AM
I try to validate text typed into a <edittext> using a regular expression. For that, I embed some javascript code (see attached file).

but I get a compilation error :
16:26: Syntax error: the token "/" was not expected at this position.

The compiler chokes on the RegExp definition.
It is valid javascript though.

Any hint ?

antun
05-18-2004, 09:54 AM
The RegExp object is one of the JavaScript objects that Laszlo does not support unfortunately.

This syntax: var foo = /myregexp/ is a shorthand way of instantiating a RegExp object, and the compiler doesn't like that.

As an alternative you could cycle through the string and test individual characters, or you could send the string to your server (e.g. a JSP) to test.

I've filed a feature request for Regular Expressions support.

-Antun

lizac
05-19-2004, 12:30 AM
Not supported ?!

What are the other Javascript objects not supported ?
Could you give a exhaustive list of supported/unsupported javascript features and if (when) they will be supported in the future ?

Thanx

antun
05-19-2004, 09:17 AM
The document you're referring to used to be linked to from the LZX Reference, but at the moment (LPS 2.1.2) is not exposed anywhere (although it does still exist) in the docs that ship with the LPS:

http://www.laszlosystems.com/lps-2.1.2/docs/lzx-reference/info-scripting.html

This is a known issue.

-Antun

UV2003
01-06-2005, 04:42 PM
This is a big bummer.

Originally posted by antun
The document you're referring to used to be linked to from the LZX Reference, but at the moment (LPS 2.1.2) is not exposed anywhere (although it does still exist) in the docs that ship with the LPS:

http://www.laszlosystems.com/lps-2.1.2/docs/lzx-reference/info-scripting.html

This is a known issue.

-Antun

lizac
01-07-2005, 12:00 AM
It appears that Regexp is not supported natively by ActionScript.
Nevertheless, some people have written Regexp classes for Flash :

http://www.jurjans.lv/flash/RegExp.html

maybe these could be used in LPS ?

redcoat
04-23-2005, 09:50 AM
Does anyone know how to do this? Or if it's even possible?

d~l
04-23-2005, 01:40 PM
I've been playing around with PHP regexp ..

You can pass your input text out (as a string) to a validate.php app ..

and then echo back the PHP regexp validated result to your text field in laszlo app.

This assumes that you have a PHP enabled server.

..

Antun referred above to this option ..

" .. or you could send the string to your server (e.g. a JSP) to test."

redcoat
04-25-2005, 05:22 AM
Hi,

Yep, I could always pass it back to the server (Java in our case), but would really like to do this solely on the client...

Anyone know if it's possible?

d~l
04-26-2005, 07:28 AM
using same approach as discussed in this thread (http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=2788) .. I found that external embedded javascript can be used to apply reg exp to Laszlo text strings passed as arguments to the embedded javascript.

External javascript opens up more functionality than the restricted javascript used in lzx apps.

e.g. RegExp object can be called as in this RegExp tutorial (http://www.devshed.com/c/a/JavaScript/Understanding-the-JavaScript-RegExp-Object/).

The (external) regexp javascript is added as an embed line in the html wrapper page .. above the embed.js entry.

e.g.


<script type="text/javascript" src="regexp.js"></script>

<script type="text/javascript" src="/lps-3.0rc1/lps/includes/embed.js"></script>


Regexp results can be passed back to lzx app as attributes to say highlight text which does not validate against regexp rules.

Holomatrix
07-11-2005, 01:36 AM
No RegExp support?, Jesus Christ :(((

What about the pattern attribute?
I used it in edittext but not all regexp won't work here. E.g. [1-9][0-9]* this should confine the edittext for digits only and not beginning with zero

Why does that not work?

Regards,
Ingo

huntedman
09-19-2005, 02:05 AM
//@field String pattern: regexp describing set of characters allowed in this field
// Restrict the characters that can be entered to a pattern
// specified by a regular expression.
//
// Currently only the expression [ ]* enclosing a set of
// characters or character ranges, preceded by an optional "^", is
// supported.
//
// examples: [0-9]* , [a-zA-Z0-9]*, [^0-9]*
// default: null
//

As found in this thread:

http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=2863&highlight=pattern+edittext

bytebodger
03-18-2006, 12:51 PM
Originally posted by d~l
I've been playing around with PHP regexp ..

You can pass your input text out (as a string) to a validate.php app ..

and then echo back the PHP regexp validated result to your text field in laszlo app.

This assumes that you have a PHP enabled server.



Another benefit of doing this is that PHP supports both of the standard RegEx formats. I really think that the back-end scripting server is a much more natural place to handle regular expression validation (assuming, of course, that you are using one in the first place).

justdan23
09-15-2008, 10:33 AM
I figured out a workaround...

Let's say I want to parse out a string's contents:
1024x768 monitor1
where the goal is an array of words:

1024
768
monitor1

Normally you might use:

var sLine = "1024x768 monitor1";
var rList = sLine.split( /[x ]/ );


But OpenLaszlo reports a 'Compiler Error' :eek: :
Syntax error: the token "/" was not expected at this position.

But there is an alternative!

var sLine = "1024x768 monitor1";
var rRegExp = new RegExp( "[x ]" ); // No slashes needed
var rList = sLine.split( rRegExp );

:cool:

onoke
09-15-2008, 04:45 PM
Hi justdan23,

Could you tell us more details about your workaround?
What was the version of your openlaszlo?
And did you call the RegExp object from the outer script, which mean was d~l said, or used ActionScript3 with SWF9 that by using v4.2b or nigthly build ?

Thank you

ono

senshi
09-16-2008, 12:30 AM
Could you tell us more details about your workaround?
What was the version of your openlaszlo?
I bet he's using the DHTML runtime, which supports RegExp natively.

And did you call the RegExp object from the outer script, which mean was d~l said, or used ActionScript3 with SWF9 that by using v4.2b or nigthly build ?
The 4.2 release will also contain RegExp for SWF8. (By the same approach explained by d~l, so the RegExp is evaluated at the browser-side and the communication from flash to browser is made through ExternalInterface). But somehow I managed to miss "String.prototype.split" when I added the SWF8 RegExp support ;). So I've just created LPP-6986 (http://www.openlaszlo.org/jira/browse/LPP-6986) to fix it.

Forgot to mention that literal RegExp expressions are not yet supported, the improvement request is filed at LPP-6872 (http://www.openlaszlo.org/jira/browse/LPP-6872).

justdan23
09-16-2008, 09:52 AM
I'm using DHTML mode with OpenLaszlo 4.1.1. This also occurs with earlier versions (as far back as 4.0.6).

As senshi pointed out, javascript provides this syntax natively. In fact, you can use this on the OpenLaszlo Debugger Console within the Eval field and it will work. The problem is with the OpenLaszlo Compiler. I should submit a JIRA ticket if someone hasn't done so already.

senshi
09-16-2008, 09:57 AM
I should submit a JIRA ticket if someone hasn't done so already.

Last sentence of my previous post ;)

justdan23
09-16-2008, 09:59 AM
I found a generic JIRA Ticket that is open for supporting RegExp in ECMA/JavaScript and added a comment about this issue:
http://www.openlaszlo.com/jira/browse/LPP-1356

The other JIRA Ticket senshi mentioned is for supporting Flash (SWF8). For DHTML support, the compiler needs only to allow the syntax as-is -- since JavaScript supports it natively.

onoke
09-16-2008, 04:44 PM
Thank you all.
I recognized it 'will' be support.

ono