{"id":1140,"date":"2010-08-10T21:38:47","date_gmt":"2010-08-10T20:38:47","guid":{"rendered":"http:\/\/www.codingfriends.com\/?p=1140"},"modified":"2010-08-10T21:38:47","modified_gmt":"2010-08-10T20:38:47","slug":"cdata_with_match_regular_expression","status":"publish","type":"post","link":"https:\/\/www.codingfriends.com\/index.php\/2010\/08\/10\/cdata_with_match_regular_expression\/","title":{"rendered":"CDATA, With, Match and Regular Expression"},"content":{"rendered":"<p><b>CDATA<\/b><\/p>\n<p>Sometimes when you get errors within your HTML <a href=\"http:\/\/validator.w3.org\/\">validation<\/a> can sometimes just get bogged down with javascript code that has not been &#8220;told&#8221; to be ignored by the parser, for example the javascript code<\/p>\n<pre lang=\"javascript\">\r\nif (a < b)\r\n<\/pre>\n<p>is fine within that context, but within HTML the < could be a start of a tag and thus would fall over with some old parsers and also the validator, so best to wrap the javascript code within the CDATA \n\n\n\n<pre lang=\"javascript\">\r\n<script type=\"text\/javascript\">\r\n<![CDATA[\r\n   if (a < b) \r\n...\r\n]]>\r\n<\/script> \r\n<\/pre>\n<p><b>WITH<\/b><\/p>\n<p>The with syntax will allow you to work on a object of a HTML form elements within having to constantly referencing the object fully, for example if you had a HTML as<\/p>\n<pre lang=\"html4strict\">\r\n<form name=\"theform\">\r\n<input id=\"theinput\"\/> \r\n<input id=\"secondinput\"\/>\r\n<\/form>\r\n<\/pre>\n<p>and so within the javascript you could do something like this without using the with statement,<\/p>\n<pre lang=\"javascript\">\r\nvar theinput = document.form.theform.theinput;\r\n<\/pre>\n<p>well if you wanted to you could use the &#8220;with&#8221; syntax and thus if you wanted to access all of the elements within that HTML object then<\/p>\n<pre lang=\"javascript\">\r\nwith (document.form.theform)\r\n{\r\n    var first = theinput;\r\n    var second = secondinput;\r\n}\r\n<\/pre>\n<p>just allot more nicer to use the objects :).<\/p>\n<p><b>Match \/ Regular expression<\/b><\/p>\n<p>Since a string within the javascript is capable of having regular expression actions applied to it, you can use the inbuilt method that is associated with the string class as such, which allows you to do regular expression, but for some reason you do not need to put in the &#8221; &#8221; around the regular expression.<\/p>\n<pre lang=\"javascript\">\r\nvar username = document.getElementById(\"username\");\r\nif (\r\n    username.match(\/.+@.+\\.com$)\r\n   ) {\r\n.... \r\n<\/pre>\n<p>will match with a regular expression so that the username has to end with .com for it to be valid!!.. not really a good test, but there you go!.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CDATA Sometimes when you get errors within your HTML validation can sometimes just get bogged down with javascript code that has not been &#8220;told&#8221; to be ignored by the parser, for example the javascript code if (a < b) is fine within that context, but within HTML the < could be a start of a &hellip; <a href=\"https:\/\/www.codingfriends.com\/index.php\/2010\/08\/10\/cdata_with_match_regular_expression\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">CDATA, With, Match and Regular Expression<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[269,64,270],"class_list":["post-1140","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-cdata","tag-regular-expression","tag-with"],"_links":{"self":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/comments?post=1140"}],"version-history":[{"count":1,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1140\/revisions"}],"predecessor-version":[{"id":1141,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/posts\/1140\/revisions\/1141"}],"wp:attachment":[{"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/media?parent=1140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/categories?post=1140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codingfriends.com\/index.php\/wp-json\/wp\/v2\/tags?post=1140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}