Validate Text only and JavaScript point

0

I'm using the Fancygrid.com Framework, and I need to validate in a Field to accept only texts and period, I'll explain. I have a field called user and the structure is: juan.cruz As you can see the field validation must accept letters and the sign (.) And also should only be written in lowercase.

I have an example of how to create a function in fancygrid and apply it to Field.

<script>
//Esta es mi función de ejemplo
var formatNumberInput = function(value){
   if(/\.$/.test(value)){
      return value;
   }

   if(/\./.test(value)){
      var splitted = value.split('.');

      if(splitted[1].length > 2){
         splitted[1] = splitted[1].substring(0, 2);
      }
      value = splitted[0] + '.' + splitted[1];
   }

   value = parseFloat(value);

   if(isNaN(value)){
      value = '';
   }

   return value;
}

//Aqui se aplica al Field
items: [{
  type: 'number',
  width:72,
  labelAlign: 'top',
  label: 'Cap(*)',
  emptyText: 'Cap',
  name: 'n_capacidad',
  checkValidOnTyping: true,
  format: { inputFn: formatNumberInput }
}],

</script>

I pass this example to you to see how is the structure that accepts Fancygrid, I am new to use frameworks and especially in javascript, that's why I need to give me a hand to create the text function with point and only lowercase . Thanks

    
asked by juanpastortapara 28.03.2018 в 18:19
source

1 answer

2
var formatNumberInput = function(value){
   return /^[a-z]+\.[a-z]+$/.test(value);
}

With this I would only return true if the value of the value variable is lowercase text followed by a period and another lowercase text I think this was what you were looking for, example pablo.alberto

    
answered by 28.03.2018 в 19:30