Jump to content

Recommended Posts

hey I need a script for no dots so when some one fills in the input filed they are not able to put in dots.

 

I have found one that removes spaces but not one that removes dots.

 

remove spaces:

<script type="text/javascript">
function nospaces(t){
if(t.value.match(/\s/g)){
alert('Sorry, you are not allowed to enter any spaces');
t.value=t.value.replace(/\s/g,'');
}
}
</script>

 

 

                       

<input class="input mediumfield" name="username" onkeyup="nospaces(this)" type="text" value="" />

 

 

 

 

 

 

 

 

 

 

 

:php_tags:

 

Link to comment
https://forums.phpfreaks.com/topic/167692-no-dots-in-input/
Share on other sites

Well, no matter what you do you also need to validate on the server page that processes the input.

 

You can handle this in different ways. Personally I don't like scripts that validate on every keystroke. Instead I will validate onblur or on submission of the form. But, to each his own. The following function should work fine.

 

<html>
<head>
<script language="JavaScript" type="text/javascript">
  function hasPeriods(value)
  {
    return value.match(/\./);
  }

  function checkDot(fieldObj)
  {
    if (hasPeriods(fieldObj.value))
    {
        alert('Periods are not allowed.');
        fieldObj.value = fieldObj.value.replace('.', '');
    }
    return;
  }
  </script>
  </head>

  <body>
    <input type="text" name="test_field" onkeyup="checkDot(this);" />
  </body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/167692-no-dots-in-input/#findComment-884435
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.