Javscript to filter dots in a texbox

Discussion in 'JavaScript' started by arun.bms08, Sep 28, 2010.

  1. #1
    i want to filter dots in a textbox using javascript if the input contains only dots.
    If the input contains dots in between alphabets and numerals the javascript should not filter.I have a javascript which filters dots even in between alphabets and numerals.
    Can any1 Help me..Below is my script:

    function addressValidation(obj)
    {
    var regex = new RegExp("[.]");
    if(obj.value.match(regex))
    {
    alert("Dot is not allowed");
    obj.focus();
    return false;
    }
    }
     
    Last edited: Sep 28, 2010
    arun.bms08, Sep 28, 2010 IP
  2. lazycoder

    lazycoder Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you want to catch only dots, use this:

    var regex = new RegExp("^\\.+$");
    Code (markup):
     
    lazycoder, Sep 28, 2010 IP