Tag Archive for check

Check if a value is numeric or not

function checkNumeric(value){
var anum=/(^d+$)|(^d+.d+$)/
if (anum.test(value))
return true;
return false;
}

source

Check or Uncheck all checkboxes on a form

function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
if(!document.forms[FormName])
return;
var objCheckBoxes = document.forms[FormName].elements[FieldName];
if(!objCheckBoxes)
return;
var countCheckBoxes = objCheckBoxes.length;
if(!countCheckBoxes)
objCheckBoxes.checked = CheckValue;
else
// set the check value for all check boxes
for(var i = 0; i < countCheckBoxes; i++)
objCheckBoxes[i].checked = CheckValue;
}

source

Php – Validar Fechas

function validarFecha( $fecha, $invertir = 1 ){
if( $invertir == 1 ) $fecha = implode( "-", array_reverse( preg_split( "/D/", $fecha ) ) );
$fecha = explode("-",$fecha);
if( sizeof( $fecha ) != 3 ) return false;
if( checkdate( $fecha[1],$fecha[0],$fecha[2]  ) ) return true;
else return false;
}

source

Does an object have a specific property?

if ("foo" in myObject) {}

source

Check if integer _value_

/**
* Check if a number is a counting number by checking if it
* is an integer primitive type, or if the string represents
* an integer as a string
*/
function is_int_val($data) {
if (is_int($data) === true) return true;
elseif (is_string($data) === true && is_numeric($data) === true) {
return (strpos($data, '.') === false);
}
return false;
}

source

Does an element exist?

<div id="bar" />
<script>
if (document.getElementById('foo') == null) {
alert('foo is missing!');
}
//or:
if ( ! document.getElementById('bar')) {
alert('bar is missing!');
}
</script>

source

Check for Include Files in PHP

<?php
$file = 'includes/filename.inc.php';
if(file_exists($file) && is_readable($file)) {
include($file);
}
?>

source

Ajax getHTTPObject function

/*Usage
* var request = getHTTPObject();
* if(request){
* AJAX CODE HERE
* }
*
* If getHTTPObject returns false, the browser isn't Ajax compatible. The if
* statement checks to see if it exists, then runs the code.
*/
function getHTTPObject() {
var xhr = false;//set to false, so if it fails, do nothing
if(window.XMLHttpRequest) {//detect to see if browser allows this method
var xhr = new XMLHttpRequest();//set var the new request
} else if(window.ActiveXObject) {//detect to see if browser allows this method
try {
var xhr = new ActiveXObject("Msxml2.XMLHTTP");//try this method first
} catch(e) {//if it fails move onto the next
try {
var xhr = new ActiveXObject("Microsoft.XMLHTTP");//try this method next
} catch(e) {//if that also fails return false.
xhr = false;
}
}
}
return xhr;//return the value of xhr
}

source

Check for e updates

#!/usr/bin/env ruby
BEGIN {$VERBOSE = true}
require 'date'
require 'fileutils'
require 'time'

LOCAL_FILE = 'e_setup.exe'
REMOTE_FILE = 'http://opencompany.org/download/e_setup.exe'
WGET_CMD = '/usr/bin/wget --spider -S'

def download_run()
`curl -R -O #{REMOTE_FILE}`
puts "Setting file permissions..."
`chmod +x #{LOCAL_FILE}`
puts "Running setup."
`cygstart #{LOCAL_FILE}`
end

unless File.exists?(LOCAL_FILE)
download_run()
exit()
end

puts "Checking modification times..."
begin
mod_time = Time.parse(%x{#{WGET_CMD} #{REMOTE_FILE} 2>&1}.split("
").grep(/Last-Modified:/)[0].split(": ")[1].chomp)
if mod_time > File.mtime(LOCAL_FILE)
puts "Remote file is newer.  Downloading..."
download_run()
else
puts "Remote file no newer than local file.  Nothing to do."
end
rescue
puts "Error during download process: ",$!
exit(false)
end

source

Browser Checker

/*-----------------------------------------------------------------------------
* Navigator
*  Example Source
document.write(
(Navigator.isWinIE())  ? 'IE' + Navigator.isWinIE() + ' (Win)' :
(Navigator.isMacIE())  ? 'IE' + Navigator.isMacIE() + ' (Mac)' :
(Navigator.isGecko())  ? 'Mozilla (' + Navigator.isGecko() + ')' :
(Navigator.isSafari()) ? 'Safari (' + Navigator.isSafari() + ')' :
(Navigator.isKDE())    ? 'KDE (' + Navigator.isKDE() + ')' :
(Navigator.isOpera())  ? 'Opera' + Navigator.isOpera() :
(Navigator.isNN4())    ? 'NN4' :
"I don't know."
);
*-------------------------------------------------------------------------- */

var Navigator = {
_getVersion: function (a, b) {
var t = navigator.userAgent.split(a)[1];
return (t) ? t.split(b)[0] : false;
},
isOpera: function () {
return (
(window.opera) ?
(document.createElementNS) ?
(document.createCDATASection) ?
(document.styleSheets) ? 9 : 8
: 7
: 6
: false
);
},
isSafari: function () {
return (document.createCDATASection && document.createElementNS) ? Navigator._getVersion('AppleWebKit/', '(') : false;
},
isKDE: function () {
return (document.createCDATASection && document.createElementNS) ? Navigator._getVersion('Konqueror/', ';') : false;
},
isGecko: function () {
return (document.createCDATASection && document.createElementNS) ? Navigator._getVersion('Gecko/', ' ') : false;
},
isNN4: function () {
return (document.layers && typeof document.layers == 'object') ? true : false;
},
isWinIE: function () {
return (
/*@cc_on @if (@_win64 || @_win32 || @_win16)
(document.getElementsByTagName) ?
(@_jscript_version > 5.6) ? 7 :
(@_jscript_version == 5.6) ? 6 :
(@_jscript_version == 5.5) ? 5.5 :
5
: 4
@else@*/false/*@end @*/
);
},
isMacIE: function () {
return (
/*@cc_on @if (@_mac && (@_PowerPC || @_mc680x0))
(document.getElementsByTagName) ? 5 : 4
@else@*/false/*@end @*/
);
}
};

source