Syntax Testing

//
//	removeInvalid: takes an input string and returns a valid DAG name string (alpha-numerics only)
//
global proc string removeInvalid(string $input, int $mode)	// 0=strip , 1=replace_
{
	string $output = "";
	for ($n = 1 ; $n < size($input)+1 ; $n++)
	{
		string $char = `substring $input $n $n`;
		if ($n == 1 && `match "[0-9]" $char` != "")
			$output += ("_"+$char);
		else	if (`match "[a-zA-Z0-9_]" $char` != "")
			$output += $char;
		else	if ($mode)
			$output += "_";
	}
	return $output;
}

2 Responses to “Syntax Testing”

  1. Raiyan Haq Says:

    I know this was posted a few years ago so you may not be keeping up with it, but I was wondering if you could query the value of a textfield, strip it of invalid characters and re-input the valid character string to the field?

  2. Naughty Says:

    sure you can, it’s a piece of cake in both MEL and Python, what exactly would you like to know about doing it? email me at nathan@(this.domain) if you like and we can discuss it properly.

Leave a Reply