EasyUI Forum
May 09, 2024, 01:43:18 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: validate a textfield just a text!!!  (Read 23700 times)
varonica
Full Member
***
Posts: 106


View Profile
« on: August 29, 2012, 09:55:07 PM »

HI admin, i tried to read again and again, but cant find how to extend validtype just a text only!!!!
Code:
    $.extend($.fn.validatebox.defaults.rules, {  
        minLength: { 
            validator: function(value, param){ 
                return value.(text) == param[0]; 
            }, 
            message: 'Please enter a text.' 
        } 
    }); 
please , help me Sad
Logged
Kevin
Jr. Member
**
Posts: 52


View Profile Email
« Reply #1 on: August 30, 2012, 11:10:20 AM »

Hi Varonica

Not sure what you would like to validate, but there are a number of examples in the forums. But here are 3 examples (the temperature validation is similar to number range).

$.extend($.fn.validatebox.defaults.rules, {
   tempRange: {
      validator: function(value, param){
         return (value >= param[0] && value <= param[1]);
      },
      message: 'Temperature must be in the range of {0}°C and {1}°C.'
   },
   numRange: {
      validator: function(value, param){
         return (value >= param[1] && value <= param[2]);
      },
      message: '{0} must be between {1} and {2}.'
   },
   maxLength: {
      validator: function(value, param){
         return value.length <= param[0];
      },
      message: 'Maximum characters allowed is {0}.'
   }
});


This is the html part;
  <input id="minTemp" name="minTemp" class="easyui-validatebox tempVal" required="true" validType="tempRange[-50,70]">
  <input name="tolerance" size="10" class="easyui-validatebox" validType="numRange['Range',0,5000]">
  <textarea name="notes" style="height:80px;width:473px;" class="easyui-validatebox" validType="maxLength[300]"> ></textarea>
Logged
varonica
Full Member
***
Posts: 106


View Profile
« Reply #2 on: August 31, 2012, 01:09:06 AM »

Hi Kevin, Thz for reply me. Perhaps u dont understand what i want to achieve clearly. Let get this straight, i have a text box and user can input some value in there but a text is possible to fill in that text box, not number!!! Sad plz help me!!
Logged
mzeddd
Full Member
***
Posts: 223



View Profile
« Reply #3 on: August 31, 2012, 07:42:35 AM »

Maybe smth like this?

Code:
$.extend($.fn.validatebox.defaults.rules, {  
        justText: { 
            validator: function(value, param){ 
                return isNaN(value);
            }, 
            message: 'Please enter a text.' 
        } 
});

http://www.w3schools.com/jsref/jsref_isnan.asp
Logged
varonica
Full Member
***
Posts: 106


View Profile
« Reply #4 on: August 31, 2012, 06:15:18 PM »

hi mzeddd, it's not working Sad !! plz help me  Cry
Logged
mzeddd
Full Member
***
Posts: 223



View Profile
« Reply #5 on: September 01, 2012, 11:38:28 AM »

it is OK for me with following code:
Code:
<script type="text/javascript">
    $.extend($.fn.validatebox.defaults.rules, { 
        justText: { 
            validator: function(value, param){ 
                return isNaN(value);
            }, 
            message: 'Please enter a text.' 
        } 
    });
</script>
<input class="easyui-validatebox" data-options="validType:'justText'">
Logged
Kevin
Jr. Member
**
Posts: 52


View Profile Email
« Reply #6 on: September 02, 2012, 10:31:48 PM »

Hi Varonica, sorry you right, I did not understand what you meant. I guess what you did want to say was "...but cant find how to extend validtype just for text only!!!!". mzeddd solution only tests the first character, so if the user enters "W8", the function passes. I guess not what you want. You can use RegExp to solve this. You can try the following;
Code:
justText: {  
   validator: function(value, param){ 
         return !value.match(/[0-9]/);
   }, 
   message: 'Please enter only text.' 

Logged
varonica
Full Member
***
Posts: 106


View Profile
« Reply #7 on: September 03, 2012, 12:13:22 AM »

Thanks, Kevin && mzeddd ^^, u guys help me alot!!
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!