cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
               <div id="css-table">
  <div id="col-1">
  <ul>
    <li><a href="#col-1-tab-1">Example 2</a></li>
  </ul>
  <div id="col-1-tab-1">
  <article>
   <h1>telephone number</h1>
   <p>
    <b>pattern:</b><br>
    <textarea class="input" id="apgexp-def" disabled></textarea>
   </p>
   <p>
    <b>phone number:</b><br>
    <textarea class="input" id="input-data"></textarea>
   </p>
    <p>
    <button id="tryit" class="tryit-button">try it</button><br>
    Experiment with some other phone number formats.
    It should accept most anything as separators.
    However, this phone number isn't protected against leading and trailing digits.
   </p>
    <p>
    <button id="leading" class="tryit-button">try it</button> with leading digits<br>
    <button id="trailing" class="tryit-button">try it</button> with trailing digits
    </p>
    <p>
    With leading or trailing digits it still finds a correct phone number in there,
    but if you are doing form validation this is probably not what you want.
    You probably only want a match if the entire string is a valid phone number.
    To accomplish this you need to add anchors at the beginning and ending of the pattern.
    </p>
    <p>
    <button id="anchors-add" class="tryit-button">add anchors</button> <button id="anchors-remove" class="tryit-button">remove anchors</button><br>
    </p>
    <p>
    Now it still matches a valid phone number and fails with leading and trailing digits.
    </p>
   <div class="discussion">
   </div>
  </article>
  </div>
  </div>
  <div id="col-2">
  <ul>
    <li><a href="#col-2-tab-1">result</a></li>
  </ul>
  <div id="col-2-tab-1">
  <article>
  <p>
  ApgExp provides a convenient display function for a quick look at the results.
  Given the set up:
  <pre>
var exp    = new ApgExp(pattern);
var result = exp.exec(string);
</pre>
simply use the function <code>result.toHtml()</code></p>
   <div id="apgexp-result"></div>
  </article>
  </div>
 </div>
  <div id="col-3">
  <ul>
    <li><a href="#col-3-tab-1">exp</a></li>
  </ul>
  <div id="col-3-tab-1">
  <article>
  <p>
  The ApgExp object retains information about the last match
  and has a convenient display function for a quick look at its values.
  Given the set up:
  <pre>
var exp    = new ApgExp(pattern);
var result = exp.exec(string);
</pre>
simply use the function <code>exp.toHtml()</code>  </p>
   <div id="apgexp-exp"></div>
  </article>
  </div>
  </div>
 </div>

            
          
!
            
              /* Pen-specific styles */
* {
	box-sizing: border-box;
}

body {
	color: #000;
	font-size: .8rem;
	line-height: 150%;
}

h1 {
	font-size: 1.75rem;
	margin: 0 0 0.75rem 0;
	font-family: 'Open Sans', sans-serif;
	font-weight: 700;
}

h2 {
	font-family: 'Open Sans', sans-serif;
	font-weight: 700;
}

article {
	font-family: 'Open Sans', sans-serif;
	font-weight: 400;
}

b {
	font-family: 'Open Sans', sans-serif;
	font-weight: 700;
}

i {
	font-family: 'Open Sans', sans-serif;
	font-style: italic;
}

textarea {
	width: 100%;
}

button {
	cursor: pointer;
	cursor: hand;
}

p.title {
	margin: 0px 0px 3px 0px;
}

a.link {
	color: #4284B0;
}

a.link:visited {
	color: #9c4be7;
}

textarea.input {
	font-size: .9rem;
	font-family: monospace;
}

/* Pattern styles */
#css-table {
	display: table;
}

#col-1 {
	display: table-cell;
	width: 40%;
	border: 1px solid #4284B0;
}

#col-2 {
  display: table-cell;
  width: 30%;
  border-width: 1px 0px;
  border-style: solid;
  border-color: #4284B0;
}

#col-3 {
  display: table-cell;
  width: 30%;
  border: 1px solid #4284B0;
}

button {
	font-size: 1em;
	font-weight: bold;
	cursor: pointer;
	cursor: hand;
	margin: 0px 0px 2px 0px;
}

button.tryit-button {
  width: 10rem;
}


#apgexp-def, #input-data {
	width: 95%;
	font-size: .9rem;
	font-family: monospace;
}

#apgexp-def {
	height: 15em;
}
            
          
!
            
              var strings = {};
var $result, $exp, $data, $abnf;

// main execution function
var execute = function() {
  var exp, result, output;
  exp = new ApgExp($abnf.val());
  result = exp.exec($data.val());
  if (result) {
    output = result.toHtml();
  } else {
    output = "<pre>result: null\n</pre>";
  }
  $exp.html(exp.toHtml());
  $result.html(output);
}

// default try-it button
var tryit = function(){
  execute();
}

// add leading digits try-it button
var leading = function(){
  $data.val(strings.leading);
  execute();
}

// add trailing digits try-it button
var trailing = function(){
  $data.val(strings.trailing);
  execute();
}

// switch to SABNF pattern with anchors
var add = function(){
  $abnf.val(strings.anchor);
}

//switch to SABNF pattern without anchors
var remove = function(){
  $abnf.val(strings.phone);
}

$(document).ready(function() {
  
  // phone number SABNF syntax (without anchors)
  strings.phone  = 'phone-number = ["("] area-code sep office-code sep subscriber\n';
  strings.phone += 'area-code    = 3digit                       ; 3 digits\n';
  strings.phone += 'office-code  = 3digit                       ; 3 digits\n';
  strings.phone += 'subscriber   = 4digit                       ; 4 digits\n';
  strings.phone += 'sep          = *3(%d32-47 / %d58-126 / %d9) ; 0-3 ASCII non-digits\n';
  strings.phone += 'digit        = %d48-57                      ; 0-9\n';

  // phone number SABNF syntax (with anchors)
  strings.anchor  = 'phone-number = %^ ["("] area-code sep office-code sep subscriber %$\n';
  strings.anchor += 'area-code    = 3digit                       ; 3 digits\n';
  strings.anchor += 'office-code  = 3digit                       ; 3 digits\n';
  strings.anchor += 'subscriber   = 4digit                       ; 4 digits\n';
  strings.anchor += 'sep          = *3(%d32-47 / %d58-126 / %d9) ; 0-3 ASCII non-digits\n';
  strings.anchor += 'digit        = %d48-57                      ; 0-9\n';

  // some input string phone numbers
  strings.input = "(333)555-1234";
  strings.leading = "22444-666-7777";
  strings.trailing = "(989)333-8888999";

  // jQuery values
  $result = $("#apgexp-result");
  $exp = $("#apgexp-exp");
  $data = $("#input-data");
  $abnf = $("#apgexp-def");

  // page setup
  $abnf.val(strings.phone);
  $data.val(strings.input);
  $("#tryit").click(execute);
  $("#anchors-add").click(add);
  $("#anchors-remove").click(remove);
  $("#leading").click(leading);
  $("#trailing").click(trailing);
  $("#col-1").tabs();
  $("#col-2").tabs();
  $("#col-3").tabs();
});

            
          
!
999px
Loading ..................

Console