Skip to main content
Participating Frequently
April 21, 2012
Question

RegExp for excluding special characters in a string.

  • April 21, 2012
  • 1 reply
  • 26188 views

Hi All,

Im using Flex RegExpValidator. Can anyone suggest me the correct expression to validate this condition?....

I have tried this expression :----- /^[^///\/</>/?/*&]+$/...But in this it is also negating the alphabets.Also I have tried with opposite condition that in the String we should have alphabets and the expression is:-- ([a-z]|[A-Z]|[0-9]|[ ]|[-]|[_])*..... Please can anyone help me on this.

Thanks in advanced to all.

Munira

This topic has been closed for replies.

1 reply

_spoboyle
Inspiring
April 23, 2012
munira06Author
Participating Frequently
April 24, 2012

Hi ,

Thanks for your reply.I have tried this condition.

And got following result:--

If you give only alphabets with no special symbols.The expression is valid

that is what is my requiremnet.

If you give only special characters .Expression is invalid what is our

requiremnet.

But if you give mixed expression of Special symbols and alphanumeric

characters it is considering it as Valid .

iwr ote:

**

Re: RegExp for excluding special characters in a string. created by

spoboyle <http://forums.adobe.com/people/spoboyle> in Flex - View the

full discussion <http://forums.adobe.com/message/4354492#4354492

_spoboyle
Inspiring
April 26, 2012

I have tried with your expression:--

But some time it shows invalid msg for special characters .

Not all time you give .

You can try with following code:--

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

xmlns:s="library://ns.adobe.com/flex/spark"

xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"

xmlns:local="*">

<fx:Script>

<![CDATA[

private var exp106:String = "^[a-zA-Z0-9 \-_]*$"

private function button1_clickHandler(event:MouseEvent):void{

regValidator.validate();

}

]]>

</fx:Script>

<fx:Declarations>

<!-- Place non-visual elements (e.g., services, value objects) here -->

<mx:RegExpValidator id="regValidator" expression=""

noMatchError="Not valid" source=""

flags="g" property="text" required="true" requiredFieldError="Please enter

string" />

</fx:Declarations>

<mx:VBox>

<s:TextInput id="textBox" />

<s:Button label="validate" click="button1_clickHandler(event)" />

</mx:VBox>

</s:Application


it would be helpful if you can stop posting Re: RegExp for excluding special characters in a string. in the middle of all you posts

and tell me what test strings are failing when they should pass or pass when they should fail