当前位置: 首页>>代码示例>>PHP>>正文


PHP validate_postcode函数代码示例

本文整理汇总了PHP中validate_postcode函数的典型用法代码示例。如果您正苦于以下问题:PHP validate_postcode函数的具体用法?PHP validate_postcode怎么用?PHP validate_postcode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了validate_postcode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validateDetails

 private function validateDetails($email, $postcode)
 {
     $valid = true;
     if (!$email || !validate_email($email)) {
         $valid = false;
     }
     if (!$postcode || !validate_postcode($postcode)) {
         $valid = false;
     }
     return $valid;
 }
开发者ID:vijo,项目名称:theyworkforyou,代码行数:11,代码来源:Simple.php

示例2: canonicalise_partial_postcode

function canonicalise_partial_postcode($pc)
{
    $pc = str_replace(' ', '', $pc);
    $pc = trim($pc);
    $pc = strtoupper($pc);
    if (validate_postcode($pc)) {
        $pc = preg_replace('#(\\d[A-Z]{2})#', '', $pc);
    } elseif (validate_partial_postcode($pc)) {
        # OK
    } else {
        err('Unexpected not full or partial postcode');
    }
    return $pc;
}
开发者ID:palfrey,项目名称:phplib,代码行数:14,代码来源:utility.php

示例3: api_getMSP_postcode

function api_getMSP_postcode($pc) {
	$pc = preg_replace('#[^a-z0-9 ]#i', '', $pc);
	if (validate_postcode($pc)) {
		$constituencies = postcode_to_constituencies($pc);
		if ($constituencies == 'CONNECTION_TIMED_OUT') {
			api_error('Connection timed out');
		} elseif (isset($constituencies['SPC'])) {
			_api_getMSP_constituency(array($constituencies['SPC'], $constituencies['SPE']));
		} elseif (isset($constituencies['WMC'])) {
			api_error('Non-Scottish postcode');
		} else {
			api_error('Unknown postcode');
		}
	} else {
		api_error('Invalid postcode');
	}
}
开发者ID:nallachaitu,项目名称:theyworkforyou,代码行数:17,代码来源:api_getMSP.php

示例4: api_getconstituency_postcode

function api_getconstituency_postcode($pc)
{
    $pc = preg_replace('#[^a-z0-9 ]#i', '', $pc);
    if (validate_postcode($pc)) {
        $constituency = postcode_to_constituency($pc);
        if ($constituency == 'CONNECTION_TIMED_OUT') {
            api_error('Connection timed out');
        } elseif ($constituency) {
            $output['name'] = html_entity_decode($constituency);
            api_output($output);
        } else {
            api_error('Unknown postcode');
        }
    } else {
        api_error('Invalid postcode');
    }
}
开发者ID:palfrey,项目名称:twfy,代码行数:17,代码来源:api_getConstituency.php

示例5: api_getConstituency_postcode

function api_getConstituency_postcode($pc)
{
    $pc = preg_replace('#[^a-z0-9 ]#i', '', $pc);
    if (!validate_postcode($pc)) {
        api_error('Invalid postcode');
        return;
    }
    $constituency = MySociety\TheyWorkForYou\Utility\Postcode::postcodeToConstituency($pc);
    if ($constituency == 'CONNECTION_TIMED_OUT') {
        api_error('Connection timed out');
        return;
    }
    if (!$constituency) {
        api_error('Unknown postcode');
        return;
    }
    return _api_getConstituency_name($constituency);
}
开发者ID:vijo,项目名称:theyworkforyou,代码行数:18,代码来源:api_getConstituency.php

示例6: api_getConstituency_postcode

function api_getConstituency_postcode($pc)
{
    $pc = preg_replace('#[^a-z0-9 ]#i', '', $pc);
    if (!validate_postcode($pc)) {
        api_error('Invalid postcode');
        return;
    }
    $constituency = postcode_to_constituency($pc, true);
    if ($constituency == 'CONNECTION_TIMED_OUT') {
        api_error('Connection timed out');
        return;
    }
    if (!$constituency) {
        api_error('Unknown postcode');
        return;
    }
    return _api_getConstituency_name($constituency);
}
开发者ID:udp12,项目名称:theyworkforyou,代码行数:18,代码来源:api_getConstituency.php

示例7: api_getconstituency_postcode

function api_getconstituency_postcode($pc) {
	$pc = preg_replace('#[^a-z0-9 ]#i', '', $pc);

  if (get_http_var('future')) {

    $new_areas = mapit_get_voting_areas($pc, 13); # Magic number 13
    if (is_object($new_areas)) { # rabx_is_error throws Notice
        api_error('Unknown postcode, or problem with lookup');
    } elseif (!isset($new_areas['WMC'])) {
        api_error('Unknown postcode, or problem with lookup');
    } else {
        $new_info = mapit_get_voting_area_info($new_areas['WMC']);
        $output['name'] = $new_info['name'];
        api_output($output);
    }

  } else {

	if (validate_postcode($pc)) {
		$constituency = postcode_to_constituency($pc);
		if ($constituency == 'CONNECTION_TIMED_OUT') {
			api_error('Connection timed out');
		} elseif ($constituency) {
                    $db = new ParlDB;
                    $q = $db->query("select constituency, data_key, data_value from consinfo
                                     where constituency = '" . mysql_real_escape_string($constituency) . "'");
                    if ($q->rows()) {
                        for ($i=0; $i<$q->rows(); $i++) {
                            $data_key = $q->field($i, 'data_key');
                            $output[$data_key] = $q->field($i, 'data_value');
                        }
                        ksort($output);
		    }
                    $output['name'] = $constituency;
		    api_output($output);
		} else {
			api_error('Unknown postcode');
		}
	} else {
		api_error('Invalid postcode');
	}

  }
}
开发者ID:henare,项目名称:theyworkforyou,代码行数:44,代码来源:api_getConstituency.php

示例8: api_getconstituency_postcode

function api_getconstituency_postcode($pc)
{
    $pc = preg_replace('#[^a-z0-9 ]#i', '', $pc);
    if (!validate_postcode($pc)) {
        api_error('Invalid postcode');
        return;
    }
    if (get_http_var('future')) {
        $xml = simplexml_load_string(file_get_contents(POSTCODE_API_URL . urlencode($pc)));
        if (!$xml || $xml->error) {
            api_error('Unknown postcode, or problem with lookup');
            return;
        }
        $output['name'] = iconv('utf-8', 'iso-8859-1//TRANSLIT', (string) $xml->future_constituency);
        api_output($output);
    } else {
        $constituency = postcode_to_constituency($pc);
        if ($constituency == 'CONNECTION_TIMED_OUT') {
            api_error('Connection timed out');
            return;
        }
        if (!$constituency) {
            api_error('Unknown postcode');
            return;
        }
        $db = new ParlDB();
        $q = $db->query("select constituency, data_key, data_value from consinfo\n                         where constituency = '" . mysql_real_escape_string($constituency) . "'");
        if ($q->rows()) {
            for ($i = 0; $i < $q->rows(); $i++) {
                $data_key = $q->field($i, 'data_key');
                $output[$data_key] = $q->field($i, 'data_value');
            }
            ksort($output);
        }
        $output['name'] = $constituency;
        api_output($output);
    }
}
开发者ID:sebbacon,项目名称:theyworkforyou,代码行数:38,代码来源:api_getConstituency.php

示例9: get_http_var

<?php

$this_page = 'boundaries';
include_once '../../includes/easyparliament/init.php';
include_once INCLUDESPATH . '../../commonlib/phplib/mapit.php';
$PAGE->page_start();
?>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<h1>Scottish and Northern Irish election constituency boundaries</h1>

<div id="boundaries">
<?php 
$pc = get_http_var('pc');
$pc = '';
# No form submissions, please
if ($pc && !validate_postcode($pc)) {
    print '<p class="error">Sorry, that doesn&rsquo;t appear to be a valid postcode.</p>';
    $pc = '';
}
if ($pc) {
    # current will have WMC key. If Scottish, has SPC and SPE too. If NI, has NIE.
    $mapit = mapit_call('postcode', $pc);
    if (is_object($mapit)) {
        # RABX error returns an object
        print '<p class="error">Afraid we couldn&rsquo;t find that postcode.</p>';
        $pc = '';
    }
}
if ($pc) {
    $current = array();
    $current_id = array();
开发者ID:udp12,项目名称:theyworkforyou,代码行数:31,代码来源:index.php

示例10: importparams_validate_postcode

function importparams_validate_postcode($pc)
{
    $pc = canonicalise_postcode($pc);
    if (validate_postcode($pc)) {
        return null;
    } else {
        return "Please enter a valid postcode, such as OX1 3DR";
    }
}
开发者ID:bruno,项目名称:openaustralia-app,代码行数:9,代码来源:importparams.php

示例11: preg_replace

<?php

# Given a postcode, return a person ID
include_once 'min-init.php';
include_once INCLUDESPATH . 'easyparliament/member.php';
$pc = $_GET['pc'];
$pc = preg_replace('#[^a-z0-9 ]#i', '', $pc);
if (validate_postcode($pc)) {
    $constituency = postcode_to_constituency($pc);
    if ($constituency == 'CONNECTION_TIMED_OUT') {
        error('Connection timed out');
    } elseif ($constituency) {
        $pid = get_person_id($constituency);
        echo 'pid,', $pid;
    } else {
        error('Unknown postcode');
    }
} else {
    error('Invalid postcode');
}
function error($s)
{
    echo 'error,', $s;
}
function get_person_id($c)
{
    $db = new ParlDB();
    if ($c == '') {
        return false;
    }
    if ($c == 'Orkney ') {
开发者ID:palfrey,项目名称:twfy,代码行数:31,代码来源:pc.php

示例12: mail

    $success = mail ($to, $subject, $message, $headers);
    return $success;
}

$errors = array();
$email = trim(get_http_var('email'));
if (!$email) {
    $errors[] = 'Please enter your e-mail address';
} elseif (!validate_email($email)) {
    $errors[] = 'Please enter a valid e-mail address';
}
$postcode = trim(get_http_var('postcode'));
$postcode = preg_replace('#[^A-Z0-9]#i', '', $postcode);
if (!$postcode) {
    $errors[] = 'Please enter your postcode';
} elseif (!validate_postcode($postcode)) {
    $errors[] = 'Please enter a valid postcode';
}

if (!$errors) {
    $constituency = postcode_to_constituency($postcode);
    if ($constituency != "connection_timed_out" && $constituency != "") {
        $token = auth_random_token();
        if (send_subscribe_email($email, $token)) {
        $q = $db->query("INSERT INTO campaigners (email, postcode, token, signup_date, constituency) VALUES ('" . mysql_real_escape_string($email) . "', '".mysql_real_escape_string($postcode)."', '".$token."', now(), '".mysql_real_escape_string($constituency)."')");

        print "<html><head><title>Check your email! - Free Our Bills - TheyWorkForYou</title></head><body>";
        freeourbills_styles();
        ?>
        <h1 class="free_our_bills_confirm">Nearly Done! Now check your email...</h1>
        <h2 class="free_our_bills_confirm">The confirmation email <strong>may</strong> take a few minutes to arrive &mdash; <em>please</em> be patient.</h2>
开发者ID:henare,项目名称:theyworkforyou,代码行数:31,代码来源:subscribe.php

示例13: checkForCommonMistakes

 private function checkForCommonMistakes()
 {
     $mistakes = array();
     if (strstr($this->data['alertsearch'], ',') > -1) {
         $mistakes['multiple'] = 1;
     }
     if (preg_match('#([A-Z]{1,2}\\d+[A-Z]? ?\\d[A-Z]{2})#i', $this->data['alertsearch'], $m) && strlen($this->data['alertsearch']) > strlen($m[1]) && validate_postcode($m[1])) {
         $this->data['postcode'] = $m[1];
         $this->data['scottish_text'] = '';
         $this->data['mp_display_text'] = '';
         if (\MySociety\TheyWorkForYou\Utility\Postcode::postcodeIsScottish($m[1])) {
             $this->data['mp_display_text'] = 'your MP, ';
             $this->data['scottish_text'] = ' or MSP';
         }
         $mistakes['postcode_and'] = 1;
     }
     $this->data['mistakes'] = $mistakes;
 }
开发者ID:vijo,项目名称:theyworkforyou,代码行数:18,代码来源:Standard.php

示例14: api_getMP_postcode

function api_getMP_postcode($pc) {
	$pc = preg_replace('#[^a-z0-9 ]#i', '', $pc);
	if (validate_postcode($pc)) {
		$constituency = postcode_to_constituency($pc);
		if ($constituency == 'CONNECTION_TIMED_OUT') {
			api_error('Connection timed out');
		} elseif ($constituency) {
			$person = _api_getMP_constituency($constituency);
			$output = $person;
			api_output($output, strtotime($output['lastupdate']));
		} else {
			api_error('Unknown postcode');
		}
	} else {
		api_error('Invalid postcode');
	}
}
开发者ID:henare,项目名称:theyworkforyou,代码行数:17,代码来源:api_getMP.php

示例15: display_search_form

function display_search_form($alert, $details = array(), $errors = array())
{
    global $this_page, $PAGE;
    $ACTIONURL = new URL($this_page);
    $ACTIONURL->reset();
    $form_start = '<form action="' . $ACTIONURL->generate() . '" method="post">
<input type="hidden" name="t" value="' . _htmlspecialchars(get_http_var('t')) . '">
<input type="hidden" name="email" value="' . _htmlspecialchars(get_http_var('email')) . '">';
    if (isset($details['members']) && $details['members']->rows() > 0) {
        echo '<ul class="hilites">';
        $q = $details['members'];
        for ($n = 0; $n < $q->rows(); $n++) {
            echo '<li>';
            echo $form_start . '<input type="hidden" name="pid" value="' . $q->field($n, 'person_id') . '">';
            echo 'Things by ';
            $name = member_full_name($q->field($n, 'house'), $q->field($n, 'title'), $q->field($n, 'given_name'), $q->field($n, 'family_name'), $q->field($n, 'lordofname'));
            if ($q->field($n, 'constituency')) {
                echo $name . ' (' . $q->field($n, 'constituency') . ') ';
            } else {
                echo $name;
            }
            echo ' <input type="submit" value="Subscribe"></form>';
            echo "</li>\n";
        }
        echo '</ul>';
    }
    if (isset($details['constituencies'])) {
        echo '<ul class="hilites">';
        foreach ($details['constituencies'] as $constituency) {
            $MEMBER = new MEMBER(array('constituency' => $constituency, 'house' => 1));
            echo "<li>";
            echo $form_start . '<input type="hidden" name="pid" value="' . $MEMBER->person_id() . '">';
            if ($details['valid_postcode']) {
                echo '<input type="hidden" name="pc" value="' . _htmlspecialchars($details['alertsearch']) . '">';
            }
            echo $MEMBER->full_name();
            echo ' (' . _htmlspecialchars($constituency) . ')';
            echo ' <input type="submit" value="Subscribe"></form>';
            echo "</li>";
        }
        echo '</ul>';
    }
    if ($details['alertsearch']) {
        echo '<ul class="hilites"><li>';
        echo $form_start . '<input type="hidden" name="keyword" value="' . _htmlspecialchars($details['alertsearch']) . '">';
        echo 'Mentions of [';
        $alertsearch = $details['alertsearch'];
        if (preg_match('#speaker:(\\d+)#', $alertsearch, $m)) {
            $MEMBER = new MEMBER(array('person_id' => $m[1]));
            $alertsearch = str_replace("speaker:{$m['1']}", "speaker:" . $MEMBER->full_name(), $alertsearch);
        }
        echo _htmlspecialchars($alertsearch) . '] ';
        echo ' <input type="submit" value="Subscribe"></form>';
        # Use original alertsearch variable here, because name replacement might introduce a comma
        if (strstr($details['alertsearch'], ',') > -1) {
            echo '<em class="error">You have used a comma in your search term &ndash; are you sure this is what you want?
You cannot sign up to multiple search terms using a comma &ndash; either use OR, or fill in this form multiple times.</em>';
        }
        if (preg_match('#([A-Z]{1,2}\\d+[A-Z]? ?\\d[A-Z]{2})#i', $alertsearch, $m) && strlen($alertsearch) > strlen($m[1]) && validate_postcode($m[1])) {
            $scottish_text = '';
            $mp_display_text = '';
            if (postcode_is_scottish($m[1])) {
                $mp_display_text = 'your MP, ';
                $scottish_text = ' or MSP';
            }
            echo '<em class="error">You have used a postcode and something else in your search term &ndash; are you sure this is what you want?
                  You will only get an alert if all of these are mentioned in the same debate. Did you mean to get alerts for when your MP' . $scottish_text . ' mentions something instead? If so click subscribe below.</em></li>';
            try {
                $MEMBER = new MEMBER(array('postcode' => $m[1]));
                // move the postcode to the front just to be tidy
                $tidy_alertsearch = $m[1] . " " . trim(str_replace("{$m['1']}", "", $alertsearch));
                $alertsearch_display = str_replace("{$m['1']} ", "", $tidy_alertsearch);
                $alertsearch = str_replace("{$m['1']}", "speaker:" . $MEMBER->person_id, $tidy_alertsearch);
                echo "<li>";
                echo $form_start . '<input type="hidden" name="keyword" value="' . _htmlspecialchars($alertsearch) . '">';
                echo 'Mentions of [';
                echo _htmlspecialchars($alertsearch_display) . '] by ' . $mp_display_text . $MEMBER->full_name();
                echo ' <input type="submit" value="Subscribe"></form>';
                if ($scottish_text) {
                    $constituencies = postcode_to_constituencies($m[1]);
                    if (isset($constituencies['SPC'])) {
                        $MEMBER = new MEMBER(array('constituency' => $constituencies['SPC'], 'house' => 4));
                        // move the postcode to the front just to be tidy
                        $alertsearch = str_replace("{$m['1']}", "speaker:" . $MEMBER->person_id, $tidy_alertsearch);
                        echo "</li><li>";
                        echo $form_start . '<input type="hidden" name="keyword" value="' . _htmlspecialchars($alertsearch) . '">';
                        echo 'Mentions of [';
                        echo _htmlspecialchars($alertsearch_display) . '] by your MSP, ' . $MEMBER->full_name();
                        echo ' <input type="submit" value="Subscribe"></form>';
                    }
                }
            } catch (MySociety\TheyWorkForYou\MemberException $e) {
                echo '<p>We had a problem looking up your representative.</p>';
            }
        }
        echo "</li></ul>";
    }
    if ($details['pid']) {
        $MEMBER = new MEMBER(array('person_id' => $details['pid']));
        echo '<ul class="hilites"><li>';
//.........这里部分代码省略.........
开发者ID:sarahs-synapse,项目名称:theyworkforyou,代码行数:101,代码来源:index.php


注:本文中的validate_postcode函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。