Data Validation at Client Site

Data Validation at Client Site

SunilgoelSunilgoel Posts: 48Questions: 19Answers: 0

Hi Support,
Is there any way to check negative value or non-numeric character in any cell.

Regards.
Sunil

Replies

  • allanallan Posts: 63,852Questions: 1Answers: 10,519 Site admin

    Hi Sunil,

    Client-side validation can be performed using the preSubmit event as shown in this example.

    You would simply use a little bit of Javascript logic to check those properties:

    editor.on( 'preSubmit', function ( e, o, action ) {
      var val = editor.field( 'myField' ).val();
    
      if ( val.match( /[^\d]/ ) ) {
        editor.field( 'myField' ).error( "Numbers only please!" );
        return false;
      }
      else if ( val < 0 ) {
        editor.field( 'myField' ).error( "Positive numbers only please!" );
        return false;
      }
    } );
    

    Of course, you'd need to do this validation at the server-side as well since it is trivial to bypass client-side validation. That's why almost all of the Editor examples focus on server-side validation.

    Regards,
    Allan

  • SunilgoelSunilgoel Posts: 48Questions: 19Answers: 0
    edited February 2017

    Hi Allan,
    if I have 15 cells to be validated then get val of each cell is very long coding required , can i use function ( e,o, action) parameter or cell number so that i can use loop and give message.

    Regards.
    Sunil

  • allanallan Posts: 63,852Questions: 1Answers: 10,519 Site admin

    If they all use the same validation, then yes, you could use a loop. Just name the fields in an array and then loop over the names, getting the value for each field in turn validating it.

    Regards,
    Allan

This discussion has been closed.