Monday, January 30, 2006

Email and Telephone regular expression

Javascript regular expression
var emailRe = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*\.(\w{2}
(comnetorgeduintmilgovarpabizaeronamecoopinfopromuseum))$/

var email = aa.uu@yom.com
if (email.match(emailRe))
document.theform.submit()

var phoneRe = /^((\+\d{1,3}(- )?\(?\d\)?(- )?\d{1,3})(\(?\d{2,3}\)?))(- )?(\d{3,4})(- )?(\d{4})(( x ext)\d{1,5}){0,1}$/

Friday, January 20, 2006

No white space in cookie string

Response.Cookies["UserData"].Value = str

The "str" SHOULDN'T contain any of these "\r", "\t", "\n", otherwise it won't set the cookie and not telling you, and you don't know what's going wrong.

UserControl input value not changing

If you use LoadControl to dynamically creating user controls. To assign new values to fields in the user control, you will need to make that assignment in the page PreRender event not page Load event.

The page Load event of the UserControl will be only called when it's added to the parent container.

Thursday, January 19, 2006

Encoding "+" etc. in URL

The Javascript escape function didn't encode + ' " / £ characters. You will need to do the replacing as follows, otherwise, you won't get what you want.

function URLEncode( url)
{  
    return escape(url).replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27').replace(/\//g,'%2F').replace(/\£/g,'%3A');
}