Regular Expression – post 01

…this post was published on 2012 December 6.

Starting from this SHP Forum post, let’s build a real example:

I inserted only one field, an input text field, identified by ID=”myfield“.
Attached to it, a javascript function verify() in onblur() event which will analyze the typed value and will answer if it is a correct value, or not !

The code for input text element is this one:
<input id =”myfield” name=”Text1″ type=”text” onblur=”verify()” />

The javascript function verify() is

function verify()
   alert(“You typed \n”+document.getElementById(‘myfield’).value);
   var re_digit =/^\d{1,4},\d{1,4}$/;
   if (document.getElementById(‘myfield’) {
      alert(“Please enter a valid value”);
      alert(‘Great:\n’+document.getElementById(‘myfield’).value+’\nit is  a  correct value!’);

This entry was posted in Javascript, RegularExpression. Bookmark the permalink.