333 views
in GUI Development by
Hi,

    i have string value with alphanumeric [ XYZ001]

   it is not accept the special character so how i add validation

var string input= "XYZ001";

Input.find( aChar, aStartIndex );  //this implemention is correct

how we filter the special character from input string.please help me to resolve this.

 

With Regards,

Ramesh.g

1 Answer

0 votes
by

Hello Ramesh.g,

I assume the string has been entered by the user and you want to verify whether the string content is correct. In such case you would implement a loop to iterate through the string characters and test character by character whether it corresponds to the expected syntax. For example, if the string is allowed to store ascii characters A-Z and digits 0-9, following could be the implementation:

var string text  = .... // your string
var int32  len   = text.length;
var bool   valid = len > 0;
var int32  inx;

for ( inx = 0; ( inx < len ) && valid; inx = inx + 1 )
  if ((( text[inx] < 'A' ) || ( text[inx] > 'Z' )) &&
      (( text[inx] < '0' ) || ( text[inx] > '9' )))
    valid = false;

if ( !valid )
  trace "The text is not valid";

I hope it helps you further.

Best regards

Paul Banach

by
Hi Paul,

Thanks for the quick update .It is working fine.
by
Hi Paul,

How the above code can be modified to validate a string which need to be contain minimum of one lower case, one upper case, one digit key and one special character. Please support.

Regards,

Sazna
by

Hello Sazna,

following could be an example demonstrating such evaluation. The string specialChars has to be adapted to your needs, depending on what you mean with special chars:

var string specialChars   = "+*#,;.:-_!ยง%%$$/()[]";
var string text           = "Some Text 7 +";
var int32  len            = text.length;
var bool   hasLowerCase   = false;
var bool   hasUpperCase   = false;
var bool   hasDigitSign   = false;
var bool   hasSpecialChar = false;
var int32  inx;

for ( inx = 0; ( inx < len ); inx = inx + 1 )
{
  var char c = text[inx];

  hasLowerCase   |= ( c >= 'a' ) && ( c <= 'z' );
  hasUpperCase   |= ( c >= 'A' ) && ( c <= 'Z' );
  hasDigitSign   |= ( c >= '0' ) && ( c <= '9' );
  hasSpecialChar |= specialChars.find( c, 0 ) >= 0;
}

var bool valid = hasLowerCase && hasUpperCase && hasDigitSign && hasSpecialChar;

Best regards

Paul Banach

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...