Skip to Content

Recently I’ve come across the topic of text input validating and well there are the many built in solutions with HTMLB elements and PHTMLB items as well however I wanted something a bit different.

Well I began searching for a way to do it, and I came across MREDKJ’s Tutorials , and they had a great “Public Domain” script available and so I figured I’d give it a shot and see if it would work for me.

Well this did the trick, this is what I wanted. This enabled me to select a field and only allow letter input in the field without an alertbox or processing and validating first.

Ok, not exactly what I wanted; I wanted basically like the doValidate of HTMLB:INPUTFIELD for type INTEGER so with a quick change to the coding, I now had it. Regular Expressions are just marvelous!

Did you catch the change? I removed the ! before reg.test(keyChar).

Now how about getting this to attach itself to my elements?

In my previous weblogs I stated how I did this, so I won’t go into a lot of detail and instead just show the code.


function emailCheck(field,msg){

       if (field.value != “”) {

           var reg = /^()@(().)()$/;

             if (!reg.test(field.value)) {


          return false;





To report this post you need to login first.


You must be Logged on to comment or reply to a post.

  1. Eddy De Clercq

    Nice weblog as always!
    Hereby an alternative code for iteger/numeric test

    function CheckNumeric(evt)
    var keyCode = evt.keyCode ? evt.keyCode :
    evt.charCode ? evt.charCode :
    evt.which ? evt.which : void 0;

    if ( keyCode > 47 && keyCode < 58 )
    return true;
    return false;

    The first one will retrieve cross platform the key pressed, the second will test if it’s numeric or not.
    Then you need to call it (example in plain HTML)



  2. Brian McKellar
    hallo Craig,

    Well done! Your weblogs slowly fall into the category “enabled reading”. This comes from the idea of enabling technology. One reads the weblogs not always for a final answer, but for the ideas of what is possible, without breaking a finger to develop it. Small gems in the toolbox!

    Now let me add some complexity: the problem with number validation (well actually with input validation), is that this is very much dependent on language and user personal settings. For example, what happens if someone has to enter 10000? In some languages the sequence 10,000 is valid, in others 10.000 is okay (My personal prefered setting would have been 10K:)

    This becomes extremely complex with dates. A German would say 10/2/2005, an American 2/10/2005 (assuming constant use of /). So what does an American living in Germany write? For these types of validation, you will have to look at the user’s personal settings, to dynamically have your validation code match the fingers at the keyboard.

    It is a complex topic.

    bye, brian


Leave a Reply