MooTools – Input Filtering


MooTools – Input Filtering


”;


MooTools can filter the user input and it can easily recognize the type of input. The basic input types are Number and String.

Number Functions

Let us discuss a few methods that will check if an input value is a number or not. These methods will also help you manipulate the number input.

toInt()

This method converts any input value to the integer. You can call it on a variable and it will try to give the regular integer from whatever the variable contains.

Let us take an example that design a web page that contain a textbox and a button named TO INT. The button will check and return the value that you entered into the textbox as real integer. If the value is not an integer, then it will return the NaN symbol. Take a look at the following code.

Example

<!DOCTYPE html>
<html>
   <head>
      <script type = "text/javascript" src = "MooTools-Core-1.6.0.js"></script>
      <script type = "text/javascript" src = "MooTools-More-1.6.0.js"></script>
      
      <script type = "text/javascript">
         var toIntDemo = function(){
            var input = $(''input'').get(''value'');
            var number = input.toInt();
            alert (''Value is : '' + number);
         }
         
         window.addEvent(''domready'', function() {
            $(''toint'').addEvent(''click'', toIntDemo);
         });
      </script>
   </head>
   
   <body>
      Enter some value: <input type = "text" id = "input" />
      <input type = "button" id = "toint" value = "TO INT"/>
   </body>
   
</html>

You will receive the following output −

Output