Jesus 'n Jim
A mainly PC (some Mac) site w/Software, Computer Repair Info, How-To's on Using Computers
Technical Support 1-360-521-2060 (my business line cell)

Programming Library

 

The code, this page, and regexp strings on this page is
Copyright © 2000,2001,2002,2003,2006,2008 Jim E. Michaels.

[email addr validation] | [nav bar] | [nav bar stylesheet]
[JavaScript code to extract URL arguments] | [PHP code for date & time conversion]


ColdFusion Email address validation code, based on RFC822 and valid URL formats. Rejects things like addresses with 2 @ signs.

<cfscript>
//----- Check for badly formed email addresses.
//----- Many people are still learning how to write email addresses, or just make a mistake.
//----- This code is based on the BNF grammar from RFC822
//----- Copyright(c)2000,2001,2002,2003 Jim E. Michaels
hasEmail=0;
emailIsValid=0;
acceptableEmailRegexp='^((([^\0-\?]+)|("(([ -!##-\[\]-~])|(\\.))*"))(\.(([^\0-\?]+)|("(([ -!##-\[\]-~])|(\\.))*")))*)\@((([^\0-\?]+)|(\[(([ -Z\^-~])|(\\.))*\]))(\.(([^\0-\?]+)|(\[(([ -Z\^-~])|(\\.))*\])))*)$';
if (parameterexists(form.email)) {
    //------ it exists, but needs verification
    hasEmail = 1;
    if (REFind(acceptableEmailRegexp, form.email) gt 0) {
        emailIsValid=1;
    }
} else {
    form.email=""; //----- even if form.email doesn't exist, at least make it expandable for convenience.
}
</cfscript>

link to page with rfc2822 regexes


Navigation Bar using table instead of graphics or buttons for speed.

 <link rel="STYLESHEET" href="/global.css" type="text/css">
  <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<TABLE BORDER="0" CELLPADDING="2" CELLSPACING="0">
  <TR>
    <TD valign="TOP" WIDTH="100" bgcolor="#FFCC99">
    <IMG src="/images/100x1.gif" WIDTH="100" HEIGHT="1" NATURALSIZEFLAG="0" align="BOTTOM">

         <table width="120" border=1 class="navbar">
          <tr><td class="navitem" OnClick="location.href='/index.html'"><a href="/index.html">HOME</a></td></tr>
          <tr><td class="navitem" OnClick="location.href='/.html'"><a href="/.html">LINK2</a></td></tr>
          <tr><td class="navitem" OnClick="location.href='/.html'"><a href="/.html">LINK3</a></td></tr>
          <tr><td class="navitem" OnClick="location.href='/.html'"><a href="/.html">LINK4</a></td></tr>
          <tr><td class="navitem" OnClick="location.href='/.html'"><a href="/.html">LINK5</a></td></tr>
          <tr><td class="navitem" OnClick="location.href='/.html'"><a href="/.html">LINK6</a></td></tr>
         </table>
<br>
         <table width="120" border=1 class="navbar">
          <tr><td class="navitemcurrent" bcolor="white" OnClick="location.href='/index.html'"><a href="/code/index.html">SUBDIRHOME</a></td></tr>
          <tr><td class="navitemcurrent" bcolor="white" OnClick="location.href='/index.html'"><a href="/code/index.html">LINK7</a></td></tr>
          <tr><td class="navitemcurrent" bcolor="white" OnClick="location.href='/index.html'"><a href="/code/index.html">LINK8</a></td></tr>
          <tr><td class="navitemcurrent" bcolor="white" OnClick="location.href='/index.html'"><a href="/code/index.html">LINK9</a></td></tr>
         </table>

</TD>
    <TD valign="TOP" WIDTH="500">
    <H1><CENTER>YOURTITLEHERE</CENTER></H1>

<p>
YOURCONTENTHERE
</p>

<p>&nbsp;</p>
    <HR align=LEFT>

    <P><IMG src="EMAILWEBGUY.GIF"
        onclick="javascript:var d='.'; var a='@';var c=':';var s='mai' + 'lto' + c + 'jimm' + a + 'integrity' + d + 'co' + 'm?subject=broken cgp web page at ' + window.location.href;window.location.href = s;"><input type="button" value="I have a question..." onclick="javascript:var d='.'; var a='@';var c=':';var s='mai' + 'lto' + c + 'jimm' + a + 'integrityonline' + d + 'co' + 'm?subject=Web page question on ' + window.location.href + ' ...';window.location.href = s;">
        <!--- when you don't have server-side scripting, this makes up for it and is reasonably secure. --->
    </TD>
  </TR>
</TABLE>


Navigation Bar Style sheet (global.css) for above.

BODY {
 font-family: Arial,Helvetica,sans-serif;
 list-style-type : square;
}

P {
 list-style-type : square;
}

TD {
 font-family: Arial,Helvetica,sans-serif;
 list-style-type : square;
}

TABLE.navbar {
 background-color:#CCFFFF;
 list-style-type : square;
 border-width: 0 0;
}

TD.navitem {
 font-family: Arial,Helvetica,sans-serif;
 padding-left : 5px;
 padding-right : 5px;
 background-color:#CCFFFF;
 list-style-type : square;
 text-align : center;
 border : 2 outset;
 cursor : hand;
}

TD.navitemcurrent {
 font-family: Arial,Helvetica,sans-serif;
 padding-left : 5px;
 padding-right : 5px;
 background-color: White;
 list-style-type : square;
 border :2 inset;
 text-align : center;
}

TH.navsubject {
 font-family: Arial,Helvetica,sans-serif;
 padding-left : 5px;
 padding-right : 5px;
 background-color: #CCCCFF;
 list-style-type : square;
}

P.indent {
 text-indent : 0.5in;
}

SPAN.title {
 font-size : large;
 font-weight : bold;
}


JavaScript code to extract URL arguments

(demo)
<script language="JavaScript" type="text/javascript">
<!--
//this function grabs the arguments from the URL, as if it was a CGI, and returns it in an array.
function getargs() {
	//find the first '?' and drops the location part of the URL.
	var sargs = new String(document.location);
	if (sargs == "") {
		var qpos = -1;
	} else {
		var qpos = sargs.indexOf("?",0);
	}
	var nularg = new Array(1);
	nularg[0] = "";
	if (qpos < 0) {
		//no args.
		return nularg;
	} else {
		sargs=sargs.substring(qpos+1);  //leave only args in the string, not including '?'
		if (sargs.indexOf("&",0) < 0) {
			//either 1 or no arguments
			var arg = new Array(1);
			arg[0] = sargs;
			if (sargs != "") {
				arg[0]=unescape(sargs);
			}
			return arg;
		} else {
			var va=sargs.split("&");
			for (var idx = 0; idx < va.length; idx++) {
				if (va[index] == "") {
					va[index] = unescape(va[index]);
				}
			}
			return va;
		}
		//should never get here
	}
	//return nularg; //should never get here.
}

	//document.write("You are using " + navigator.appName + " " + navigator.appVersion);
	//so what charset do macs use?
function writechartable(nfrom,nto,ncols,charcolor,charsize,fnt) {
	if (ncols < 1 || nto<1 || nfrom>nto || nfrom<1) {
		document.write("programmer error - writechartable(nfrom,nto,ncols) paramters are out of range. nfrom=",nfrom ,",nto=",nto,",ncols=",ncols,",charcolor=",charcolor,",charsize=",charsize,",fnt=",fnt,".<br>");
		return;
	}
	var c,col,done;
	document.write("<table>");
	col=0;
	done=false;
	for (c = nfrom; !done; c++, col=(col+1)%ncols) {
		if (0==col) {
			document.write("<tr>");
		}
		document.write("<td>",c.toString(),"<font face=Tahoma size='",charsize,"' color='",charcolor,"'> &#", c.toString(), ";</font></td>");
		if (ncols-1==col) {
			document.write("</tr>");
			done=c > nto;
		}
	}
	document.write("</table>");
}	
// -->
</script>

PHP code for mysql <--> 12hr/24hr USA date & time conversion

function ampm($tm) {
 //converts military time to am/pm
 if ($tm=="") {
    return "";
 }
 $ab = explode(":", $tm);
 $ap = $ab[0]<12?" am":" pm";
 if ("00" == $ab[0]) {$ab[0]=24;}
 if ($ab[0]>12) {$ab[0]-=12;}
 return "$ab[0]:$ab[1] $ap";
}



function militarytime($t) {	
	//convert 12-hour time format to MySQL 24-hour time format
 	$i=strpos($t,"a");
	if (false==$i){$i=strpos($t,"A");}
	if (false==$i){$i=strpos($t,"p");}
	if (false==$i){$i=strpos($t,"P");}
	echo $i;
	$tm=array(); //space-separated strings
	$tms=array('00','00'); //time components separated by :
 	if ($i) { //has am/pm
	 	if (strchr($t," ")) {
			$tm=explode(" ",$t);
			$tms=explode(":",$tm[0]);
		} else {//no space before am/pm.  example: 1:00a
			$tms=explode(":",substr($t,0,$i)); //1:00
			$tm[0]=implode(":",$tms);
		}
		echo $t[$i];
		if ('a'==strtolower($t[$i])) {
			$t=$tm[0];
			//correct the hour
			if ('12'==$tms[0]) { $tms[0]='00'; }
		} else { //pm
			//correct the hour
			if ('12'!=$tms[0]) { $tms[0]+=12; }
		}
		if (count($tms)<2) {
			$tms[1]='00';
		}
		return implode(":",$tms);
	}
	//already in military time
	return $t;
}

function date2mysql($d) {
	//convert USA style mm/dd/yy date to MySQL DB-friendly yyyy-mm-dd
 	if (strchr($d,"/")) {
		$dt=explode("/",$d);
		if (3==count($dt)) {
			$d="$dt[2]-$dt[0]-$dt[1]";
		} else { //assume 2 - they left the year out
			$today = getdate();
			$year=$today['year'];
			$d="$year-$dt[0]-$dt[1]";
		}
	}
	return $d;
}

function mysql2date($d) {
	if ($d == NULL ||
	    $d == "" ||
	    $d == "null" ||
		$d == "NULL" ||
		$d == "(null)" ||
		$d == "(NULL)") {
		return "00/00/0000";
	}
	//convert MySQL date format yyyy-mm-dd to USA style mm/dd/yyyy
 	if (strchr($d,"-")) {
		$dt=explode("-",$d);
		if (3==count($dt)) {
			return "$dt[1]/$dt[2]/$dt[0]";
		} else { //assume 2 - they left the year out
			return implode("/",$dt);
		}
	}
	return $d;
}

function mysql2alwaysmysqldate($d) {
	if ($d == NULL ||
	    $d == "" ||
	    $d == "null" ||
		$d == "NULL" ||
		$d == "(null)" ||
		$d == "(NULL)") {
		return "0000-00-00";
	}
	//convert MySQL date format yyyy-mm-dd to USA style mm/dd/yyyy
	return $d;
}




This code section is not copyrighted. is is here for reference.
 
  
>> How can I convert some html entities (polish) to a
>> character which I can use in a javascript alert?
>>
>> The entities are:
>> &#x0144;
>> &#x0119;
>
>  "\u0144"
>  "\u0119"

> etc...
>
>
> Bye.
>   Jasen
 
the following also works.
var s = new String();
s=String.fromCharCode(0x0144,0x0119,0x0144,0x0105,0x017C,0x015B,0x0107);
alert(s);
you can concatenate strings with +