Function:
; #FUNCTION# ==================================================================================================================== ; Name ..........: _StringIsValid ; Description ...: Checks whether a string contains a set of characters and is valid. ; Syntax ........: _StringIsValid($sString[, $sPattern = '\/|:<>"']) ; Parameters ....: $sString - A string. ; $sPattern - [optional] A pattern of characters that shouldn't be present. Default is '\/|:<>"'. ; Return values .: Success: True ; Failure: False ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _StringIsValid($sString, $sPattern = '\/|:<>"') $sPattern = StringReplace($sPattern, '\E', 'E\') $sPattern = StringReplace($sPattern, '\Q', 'Q\') Return StringRegExp($sString, '[\Q' & $sPattern & '\E]') = 0 EndFunc ;==>_StringIsValid
Example use of Function:
#include <Constants.au3> Example() Func Example() ConsoleWrite('String is ... ' & _StringIsValid('This is a simple string which will be valid!') & @CRLF) ; Returns True, using pre-defined characters. ConsoleWrite('String is ... ' & _StringIsValid('<This is a simple string which will be invalid!>') & @CRLF) ; Returns False, using pre-defined characters. ConsoleWrite('String is ... ' & _StringIsValid('<This is a simple string which will be valid!>', '|\') & @CRLF) ; Returns True, because we defined the invalid characters of | & \ If _StringIsValid('This is a simple string which will be valid!') Then MsgBox($MB_SYSTEMMODAL, '', 'The string is valid.') Else MsgBox($MB_SYSTEMMODAL, '', 'The string is not valid.') EndIf If _StringIsValid("This is a simple string which won:t be valid!") Then MsgBox($MB_SYSTEMMODAL, '', 'The string is valid.') Else MsgBox($MB_SYSTEMMODAL, '', 'The string is not valid.') EndIf EndFunc ;==>Example
Example 2: This Returns an @error Value. Thanks to user supersonic.
Edited by guinness, 04 April 2013 - 07:34 AM.





