Question: Can any one tell me the regular expression for textfield which should not allow following characters and can accept other special characters,alphabets,numbers and so on :

```
+ - && || ! ( ) { } [ ] ^ " ~ * ? : \ @ &

```

Answer: 
this will not allow string that contains any of the characters in any part of the string mentioned above.

```
^(?!.*[+\-&|!(){}[\]^"~*?:@&]+).*$

```

* [See Here](https://dl.dropboxusercontent.com/u/29622718/regex1.JPG)

Brief Explanation

* Assert position at the beginning of a line (at beginning of the string or after a line break character) `^`
* Assert that it is impossible to match the regex below starting at this position (**negative lookahead**) `(?!.*[+\-&|!(){}[\]^"~*?:@&]+)`
	+ Match any single character that is not a line break character `.*`
		- Between zero and unlimited times, as many times as possible, giving back as needed (greedy) `*`
	+ Match a single character present in the list below `[+\-&|!(){}[\]^"~*?:@&]+`
		- Between one and unlimited times, as many times as possible, giving back as needed (greedy) `+`
		- The character "+" `+`
		- A "-" character `\-`
		- One of the characters `&|!(){}[” «&|!(){}[`
		- A "]" character `\]`
		- One of the characters `^"~*?:@&” «^"~*?:@&`
* Match any single character that is not a line break character `.*`
	+ Between zero and unlimited times, as many times as possible, giving back as needed (greedy) `*`
* Assert position at the end of a line (at the end of the string or before a line break character) `$`
I recognize those as the characters which need to be escaped for Solr. If this is the case, and if you are coding in PHP, then you should use my [PHP utility functions](https://github.com/dotancohen/utility-functions) from Github. Here is one of the Solr functions from there:

```
/**
* Escape values destined for Solr
*
* @author Dotan Cohen
* @version 2013-05-30
*
* @param value to be escaped. Valid data types: string, array, int, float, bool
* @return Escaped string, NULL on invalid input
*/

function solr_escape($str)
{
    if ( is_array($str) ) {
        foreach ( $str as &$s ) {
            $s = solr_escape($s);
        }

        return $str;
    }

    if ( is_int($str) || is_float($str) || is_bool($str) ) {
        return $str;
    }

    if ( !is_string($str) ) {
        return NULL;
    }

    $str = addcslashes($str, "+-!(){}[]^\"~*?:\\");
    $str = str_replace("&&", "\\&&", $str);
    $str = str_replace("||", "\\||", $str);

    return $str;
}

```