{"id":26137,"date":"2010-01-12T20:55:53","date_gmt":"2010-01-13T00:55:53","guid":{"rendered":"https:\/\/www.bu.edu\/tech\/?page_id=26137"},"modified":"2013-05-23T11:45:49","modified_gmt":"2013-05-23T15:45:49","slug":"validation","status":"publish","type":"page","link":"https:\/\/www.bu.edu\/tech\/services\/cccs\/websites\/www\/non-wordpress\/marconi\/how-to\/validation\/","title":{"rendered":"How to Validate Input"},"content":{"rendered":"<p>On this page:<\/p>\n<ul>\n<li><a href=\"#require\">Require a Field<\/a><\/li>\n<li><a href=\"#require-match\">Require that Two Fields Match<\/a><\/li>\n<li><a href=\"#require-validate\">Require that a Field Match a Given Format<\/a><\/li>\n<li><a href=\"#imperius\">Display Error Messages on Your Form<\/a><\/li>\n<li><a href=\"#custom\">Display Custom Error Messages<\/a><\/li>\n<\/ul>\n<p><a name=\"require\"><\/a><\/p>\n<h3>Require a Field<\/h3>\n<ol>\n<li>Add this line of code to your Telegraph configuration file:<br \/>\n<code>&lt;directive action=\"require\" field=\"<strong>required-field-name<\/strong>\" \/&gt;<\/code><\/p>\n<ul>\n<li>Example:<br \/>\n<code>&lt;directive action=\"require\" field=\"email\" \/&gt;<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>This will require that a field contain a value\/input, either by typing into a field, selecting a checkbox or toggling a radio button.<br \/>\n<a name=\"require-match\"><\/a><\/p>\n<h3>Require that Two Fields Match<\/h3>\n<ol>\n<li> Add this line of code to your Telegraph configuration file:<br \/>\n<code>&lt;directive action=\"match\" field1=\"<strong>first-field-to-match<\/strong>\" field2=\"<strong>second-field-to-match<\/strong>\/&gt;<\/code>&gt;<\/li>\n<li>Replace<strong> first-field-to-match <\/strong>and <strong>second-field-to-match<\/strong> with the two fields which need to be matched (e.g., an email address).\n<ul>\n<li>Example:<br \/>\n<code>&lt;directive action=\"match\" field1=\"email1\" field2=\"email2\" \/&gt;<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><a name=\"require-validate\"><\/a><\/p>\n<h3>Require that a Field Match a Given Format<\/h3>\n<ol>\n<li>Add the <strong>format<\/strong> parameter to your &lt;directive action=&#8221;require&#8221; \/&gt; tag. You can use any of the following &#8220;canned&#8221; formats:<br \/>\n<table border=\"0\">\n<tbody>\n<tr>\n<td>email<\/td>\n<td>A properly-formatted email address.<\/td>\n<\/tr>\n<tr>\n<td>ssn<\/td>\n<td>A Social Security Number. <strong>Note: Social Security Numbers should only be collected when using <a href=\"www-staging.bu.edu\/tech\/web\/departments\/non-wordpress\/telegraph\/how-to\/send-email\/#pgp\">PGP Encryption<\/a>.<\/strong><\/td>\n<\/tr>\n<tr>\n<td>phone<\/td>\n<td>A 7-digit or 10-digit Phone Number.<\/td>\n<\/tr>\n<tr>\n<td>zip<\/td>\n<td>A 5-digit ZIP or 9-digit ZIP+4.<\/td>\n<\/tr>\n<tr>\n<td>url<\/td>\n<td>Any correctly-formatted website address.<\/td>\n<\/tr>\n<tr>\n<td>bu-url<\/td>\n<td>A valid and working URL for a page on the BU Web.<\/td>\n<\/tr>\n<tr>\n<td>bu-login<\/td>\n<td>A valid and current BU Kerberos login name.<\/td>\n<\/tr>\n<tr>\n<td>number<\/td>\n<td>Any number, including one with decimal values.<\/td>\n<\/tr>\n<tr>\n<td>positive<\/td>\n<td>Any positive numbers, including one with decimal values.<\/td>\n<\/tr>\n<tr>\n<td>negative<\/td>\n<td>Any negative numbers, including one with decimal values; this must be represented using a hyphen for the minus sign.<\/td>\n<\/tr>\n<tr>\n<td>integer<\/td>\n<td>Any integer.<\/td>\n<\/tr>\n<tr>\n<td>positive-integer<\/td>\n<td>Any positive integer.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ul>\n<li>Example #1 &#8211; Email:\n<ul>\n<li><code>&lt;directive action=\"require\" field=\"email\" format=\"email\" \/&gt;<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<ul>\n<li>Example #2 &#8211; Phone Number:\n<ul>\n<li><code>&lt;directive action=\"require\" field=\"phone\" format=\"phone\" \/&gt;<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><a name=\"imperius\"><\/a><\/p>\n<h3>Display Error Messages on Your Form<\/h3>\n<ol>\n<li>To show error messages on the form web page, add the <strong>imperius<\/strong> directive to your Telegraph configuration file:<em><br \/>\n<\/em><code>&lt;directive action=\"imperius\" filename=\"<strong>my-form-filename<\/strong>\" \/&gt;<\/code><\/p>\n<ul>\n<li>Example:<code><br \/>\n&lt;directive action=\"imperius\" filename=\"index.shtml\" \/&gt;<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>Error messages will display immediately underneath the opening <strong><code>&lt;form&gt;<\/code><\/strong> tag.<br \/>\nIf you are creating a form for a WordPress site, replace the <strong>filename<\/strong> parameter with <strong>url<\/strong> and provide the path to your WordPress page.<\/p>\n<ul>\n<li>\n<ul>\n<li>Example:<br \/>\n<span style=\"font-family: monospace;\">&lt;directive action=&#8221;imperius&#8221; url=&#8221;\/cragglerock\/form\/&#8221; \/&gt;<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><a name=\"error\"><\/a><\/p>\n<h3>Display Custom Error Messages<\/h3>\n<ol>\n<li>To show custom error message when a required field isn&#8217;t filled out or doesn&#8217;t match a required format, add an <strong>error<\/strong> parameter to the <strong>action=&#8221;require&#8221;<\/strong> tag:<em><br \/>\n<\/em><code>&lt;directive action=\"require\" field=\"<strong>required-field<\/strong>\" format=\"<strong>required-field<\/strong>\" error=\"<strong>error-message<\/strong>\" \/&gt;<\/code><em> <\/em><\/p>\n<ul>\n<li>Example:<br \/>\n<code>&lt;directive action=\"require\" field=\"email\" format=\"email\" error=\"Please enter a valid email address.\" \/&gt;<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>On this page: Require a Field Require that Two Fields Match Require that a Field Match a Given Format Display Error Messages on Your Form Display Custom Error Messages Require a Field Add this line of code to your Telegraph configuration file: &lt;directive action=&#8221;require&#8221; field=&#8221;required-field-name&#8221; \/&gt; Example: &lt;directive action=&#8221;require&#8221; field=&#8221;email&#8221; \/&gt; This will require that&#8230;<\/p>\n","protected":false},"author":1282,"featured_media":0,"parent":26082,"menu_order":5,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages\/26137"}],"collection":[{"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/users\/1282"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/comments?post=26137"}],"version-history":[{"count":26,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages\/26137\/revisions"}],"predecessor-version":[{"id":67242,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages\/26137\/revisions\/67242"}],"up":[{"embeddable":true,"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/pages\/26082"}],"wp:attachment":[{"href":"https:\/\/www.bu.edu\/tech\/wp-json\/wp\/v2\/media?parent=26137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}