Re: How to use javascript's regular expression by jsni?

2014-11-20 Thread Alex Luya
Sorry,there is typing mistake in my question:the returning type of 
reEmail() isn't boolean but String,and my code is:
  
 private native String reEmail()/-*{

 return 
^(([^()[\]\\.,;:\s@\]+(\.[^()[\]\\.,;:\s@\]+)*)|(\.+\...@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$;
}-*/;


and it doesn't work.



On Thursday, November 20, 2014 3:18:32 PM UTC+8, Alex Luya wrote:

  Hello:
  Similar question has been asked here: How to pass a regular 
 expression as a function parameter 
 http://stackoverflow.com/questions/11143702/how-to-pass-a-regular-expression-as-a-function-parameter,
  
 but I can't get it work by JSNI.

 This is the string of the regular expression that will be used to test 
 email:

   
 ^(([^()[\]\\.,;:\s@\]+(\.[^()[\]\\.,;:\s@\]+)*)|(\.+\))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$
  
 ))@((%5C[[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C])%7C(([a-zA-Z%5C-0-9]+%5C.)+[a-zA-Z]%7B2,%7D))$

 and if putting it to firebug execute like this:

  
 /^(([^()[\]\\.,;:\s@\]+(\.[^()[\]\\.,;:\s@\]+)*)|(\.+\))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$
  
 ))@((%5C[[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C])%7C(([a-zA-Z%5C-0-9]+%5C.)+[a-zA-Z]%7B2,%7D))$/.test(t...@domain.com
  t...@domain.com)

 it will give what I want,but If wrapping it to a JSNI method:

 private native boolean reEmail()/-*{
  return 
 ^(([^()[\]\\.,;:\s@\]+(\.[^()[\]\\.,;:\s@\]+)*)|(\.+\))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$
  
 ))@((%5C[[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C])%7C(([a-zA-Z%5C-0-9]+%5C.)+[a-zA-Z]%7B2,%7D))$;
 }-*/;

 then passing it to the function:

private native boolean validate(String value, String regexp)/-*{
//escape special characters
var re=regexp.replace(/([-()\[\]{}+?*.$\^|,:#!\\])/g, 
 '\\$1').replace(/\x08/g, '\\x08');
return new RegExp(re,'g').test(value)
}-*/;

 like this:

   validate(t...@domain.com t...@domain.com,reEmail());

 It will give me false.Please tell what mistakes I have made,thanks.
  

-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.


Re: How to use javascript's regular expression by jsni?

2014-11-20 Thread Thomas Broyer
\s and \[ (among others) in a JS string are equivalent to s and [, 
so you have to escape the backslash.
Also, your escape special characters is messing with your regexp, turning 
your [0-9]{1,3} into \[0\-9\]\{1\,3\} (among others) which does not mean 
the same thing at all.

Or maybe just use a RegExp literal like you do in Firebug?

On Thursday, November 20, 2014 9:07:24 AM UTC+1, Alex Luya wrote:

 Sorry,there is typing mistake in my question:the returning type of 
 reEmail() isn't boolean but String,and my code is:
   
  private native String reEmail()/-*{

  return 
 ^(([^()[\]\\.,;:\s@\]+(\.[^()[\]\\.,;:\s@\]+)*)|(\.+\...@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$;
 }-*/;


 and it doesn't work.

 

 On Thursday, November 20, 2014 3:18:32 PM UTC+8, Alex Luya wrote:

  Hello:
  Similar question has been asked here: How to pass a regular 
 expression as a function parameter 
 http://stackoverflow.com/questions/11143702/how-to-pass-a-regular-expression-as-a-function-parameter,
  
 but I can't get it work by JSNI.

 This is the string of the regular expression that will be used to test 
 email:

   
 ^(([^()[\]\\.,;:\s@\]+(\.[^()[\]\\.,;:\s@\]+)*)|(\.+\))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$
  
 ))@((%5C[[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C])%7C(([a-zA-Z%5C-0-9]+%5C.)+[a-zA-Z]%7B2,%7D))$

 and if putting it to firebug execute like this:

  
 /^(([^()[\]\\.,;:\s@\]+(\.[^()[\]\\.,;:\s@\]+)*)|(\.+\))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$
  
 ))@((%5C[[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C])%7C(([a-zA-Z%5C-0-9]+%5C.)+[a-zA-Z]%7B2,%7D))$/.test(t...@domain.com
  t...@domain.com)

 it will give what I want,but If wrapping it to a JSNI method:

 private native boolean reEmail()/-*{
  return 
 ^(([^()[\]\\.,;:\s@\]+(\.[^()[\]\\.,;:\s@\]+)*)|(\.+\))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$
  
 ))@((%5C[[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C])%7C(([a-zA-Z%5C-0-9]+%5C.)+[a-zA-Z]%7B2,%7D))$;
 }-*/;

 then passing it to the function:

private native boolean validate(String value, String regexp)/-*{
//escape special characters
var re=regexp.replace(/([-()\[\]{}+?*.$\^|,:#!\\])/g, 
 '\\$1').replace(/\x08/g, '\\x08');
return new RegExp(re,'g').test(value)
}-*/;

 like this:

   validate(t...@domain.com t...@domain.com,reEmail());

 It will give me false.Please tell what mistakes I have made,thanks.
  


-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.


How to use javascript's regular expression by jsni?

2014-11-19 Thread Alex Luya

Hello:
 Similar question has been asked here: How to pass a regular 
expression as a function parameter 
http://stackoverflow.com/questions/11143702/how-to-pass-a-regular-expression-as-a-function-parameter, 
but I can't get it work by JSNI.


This is the string of the regular expression that will be used to test 
email:


|   
^(([^()[\]\\.,;:\s@\]+(\.[^()[\]\\.,;:\s@\]+)*)|(\.+\))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$
|

and if putting it to firebug execute like this:

|  
/^(([^()[\]\\.,;:\s@\]+(\.[^()[\]\\.,;:\s@\]+)*)|(\.+\))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(t...@domain.com)
|

it will give what I want,but If wrapping it to a JSNI method:

| private native boolean reEmail()/-*{
 return 
^(([^()[\]\\.,;:\s@\]+(\.[^()[\]\\.,;:\s@\]+)*)|(\.+\))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$;
}-*/;
|

then passing it to the function:

|private native boolean validate(String value, String regexp)/-*{
   //escape special characters
   var re=regexp.replace(/([-()\[\]{}+?*.$\^|,:#!\\])/g, 
'\\$1').replace(/\x08/g, '\\x08');
   return new RegExp(re,'g').test(value)
   }-*/;
|

like this:

|   validate(t...@domain.com,reEmail());
|

It will give me false.Please tell what mistakes I have made,thanks.

--
You received this message because you are subscribed to the Google Groups Google 
Web Toolkit group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.


Re: How to use javascript's regular expression by jsni?

2014-11-19 Thread Alberto Mancini
Hi,

boolean reEmail()

but you are using as a String in  validate(t...@domain.com
t...@domain.com,reEmail());

then

regexp in the validate method is 're' when used but 'regexp' as a parameter.





On Thu Nov 20 2014 at 8:18:32 AM Alex Luya alexander.l...@gmail.com wrote:

  Hello:
  Similar question has been asked here: How to pass a regular
 expression as a function parameter
 http://stackoverflow.com/questions/11143702/how-to-pass-a-regular-expression-as-a-function-parameter,
 but I can't get it work by JSNI.

 This is the string of the regular expression that will be used to test
 email:

   
 ^(([^()[\]\\.,;:\s@\]+(\.[^()[\]\\.,;:\s@\]+)*)|(\.+\))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$
  
 ))@((%5C[[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C])%7C(([a-zA-Z%5C-0-9]+%5C.)+[a-zA-Z]%7B2,%7D))$

 and if putting it to firebug execute like this:

  
 /^(([^()[\]\\.,;:\s@\]+(\.[^()[\]\\.,;:\s@\]+)*)|(\.+\))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$
  
 ))@((%5C[[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C])%7C(([a-zA-Z%5C-0-9]+%5C.)+[a-zA-Z]%7B2,%7D))$/.test(t...@domain.com
  t...@domain.com)

 it will give what I want,but If wrapping it to a JSNI method:

 private native boolean reEmail()/-*{
  return 
 ^(([^()[\]\\.,;:\s@\]+(\.[^()[\]\\.,;:\s@\]+)*)|(\.+\))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$
  
 ))@((%5C[[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C.[0-9]%7B1,3%7D%5C])%7C(([a-zA-Z%5C-0-9]+%5C.)+[a-zA-Z]%7B2,%7D))$;
 }-*/;

 then passing it to the function:

private native boolean validate(String value, String regexp)/-*{
//escape special characters
var re=regexp.replace(/([-()\[\]{}+?*.$\^|,:#!\\])/g, 
 '\\$1').replace(/\x08/g, '\\x08');
return new RegExp(re,'g').test(value)
}-*/;

 like this:

   validate(t...@domain.com t...@domain.com,reEmail());

 It will give me false.Please tell what mistakes I have made,thanks.

 --
 You received this message because you are subscribed to the Google Groups
 Google Web Toolkit group.
 To unsubscribe from this group and stop receiving emails from it, send an
 email to google-web-toolkit+unsubscr...@googlegroups.com.
 To post to this group, send email to google-web-toolkit@googlegroups.com.
 Visit this group at http://groups.google.com/group/google-web-toolkit.
 For more options, visit https://groups.google.com/d/optout.


-- 
You received this message because you are subscribed to the Google Groups 
Google Web Toolkit group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.