another javascript

Results 1 to 2 of 2

Thread: another javascript

  1. #1
    Join Date
    Dec 1969

    Default another javascript

    Can anyone tell me what this equates to.<BR><BR>var nametest = /^[a-z0-9-]+.([a-z0-9-]+.)?[a-z]{2,3}:?d*$/i;<BR><BR>Thanks

  2. #2
    Join Date
    Dec 1969

    Default You mean regular expression..

    The syntax, as is, is JS. But the pattern could be used in any system that supports regular expressions.<BR><BR>/^[a-z0-9-]+.([a-z0-9-]+.)?[a-z]{2,3}:?d*$/i;<BR><BR>^ == Look for the pattern at the beginning of the test string.<BR> (In other words, don&#039;t allow any junk before what we are looking for.)<BR><BR>[a-z0-9-] == Look for any letters *or* numbers *or* a minus sign<BR>+ == in fact, look for *one or more* of those characters<BR>. == look for a period<BR><BR>So up to here, we have insisted on finding one or more alphanumeric (or minus) characters followed by a period. Strings such as<BR> 1.<BR> abcdefghijklmnopqrstuvwxyz.<BR> f-u-n-9-9-.<BR>are all "legal" and will pass the test.<BR><BR>[a-z0-9-]+. == look familiar? Same thing again!<BR>(...)? == means all the stuff inside the parens is optional.<BR>([a-z0-9-]+.)? == so, OPTIONALLY look for that same pattern as above <BR><BR>[a-z] == look for any one letter...<BR>{2,3} == ...either 2 or 3 times.<BR>:? == a colon character is optional<BR>d* = expect zero or more digits<BR><BR>$ == the string to be tested must then end (no junk after what we test for)<BR><BR>/i == ignore case (so all the places where [a-z] were used *also* imply [A-Z]<BR><BR>So all of that says that the following strings will pass the regular expression test:<BR><BR><BR> www.mysite.aa:8080<BR><BR><BR>And all of those look pretty good. BUT...<BR><BR>But the following will *ALSO* pass the test!<BR> -.-.zz: [because the d* means the digits are optional]<BR> 9.aaa9018 [because the :? means the question mark is optional]<BR> <BR>AND...<BR><BR>And the following legit addresses will *NOT* pass the test:<BR><BR><BR><BR>SO...<BR><BR>It&#039;s actually a pretty crappy test for a web site address, isn&#039;t it?<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts