Page 1 of 1

what's the meaning of this code

Posted: Thu May 29, 2008 9:33 am
by junjustkim
Hi to all, I have found some script and I don't know the meaning especially with the especiall chatacter, I highlighted with color blue. This is my second week for learning web desing using php. I already look at the javascript but I didn't found it. Actually I found this code insside filename.js so my understanding is about with javascript. Please take a look at the code and give me an idea.

Thanks in advance

Code: Select all

 
// validators ------------------------------------------------------------------
    
function isEmpty (s) {
    var p = /\S+/;
    return !p.test(s);
}
 
function isEmail(string) {
    if (string.search[color=#0000BF](/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1[/color])
        return true;
    else
        return false;
}
 
function isAlphaNum(string) {
    if (string.search(/^[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}
 
function isNum(string) {
    if (string.search(/^[0-9]+$/) != -1)
        return false;
    else
        return true;
}
 
function isExecutable (s) {
    var p = [color=#0000BF]/\.(bat|com|dll|exe|vbs)$/i;[/color]
    return p.test(s);
}
 
function isImage (s) {
    var p = /\.(gif|jpg)$/i;
    return p.test(s);
}
 
function isUrl (s) {
    var p = /^(http|https|ftp):\/\/\S+\.[^\.\s]{2,4}(\/\S*)?$/i;
    return p.test(s);
}
 

Re: what's the meaning of this code

Posted: Thu May 29, 2008 9:44 am
by onion2k
It's some validation functions to test if strings match against some regular expressions.

Re: what's the meaning of this code

Posted: Thu May 29, 2008 9:44 am
by VladSun
It's called "regular expression" - google it :)
Also it's not PHP, but a JavaScript code :)

Re: what's the meaning of this code

Posted: Thu May 29, 2008 9:48 am
by pickle
Moving thread to Client Side.

Re: what's the meaning of this code

Posted: Thu May 29, 2008 11:30 pm
by junjustkim
Thank you very much for all your replied, But I want to know the meaning of each character so that later I could used this if needed. Where tutorial I can find this code.

Thanks

Re: what's the meaning of this code

Posted: Fri May 30, 2008 2:45 am
by onion2k
It's called "regular expression" - google it

Re: what's the meaning of this code

Posted: Fri May 30, 2008 7:04 pm
by junjustkim
Thank you so much, Now I know.

Until next post.