restricting character set in a Textinput field - apache-flex

I have a TextInput field that should be restricted to either capital letters, lowercase letters, numbers and underscores. This is the code I'm trying to use to restrict characters:
restrict="\\A-Z\\a-z\\0-9\\ \\_\\-"
I'm using MXML for this Textinput component.
Unfortunately this does not restrict the \ character, which is the last character I'd like to restrict.
How can I add the backslash to the list of restricted characters?
Thanks
Stephen

Actually found the solution I've amended the restrict code to:
restrict="A-Za-z0-9 _\-"
I took out all the back slashes which I thought or was using as delimiters.
Works fine now.

Related

I am receiving \u200b in certain translations from the google-translate api

I am new to using the Google translate API and during testing we noticed that for some translations (I have not been able to find a pattern yet) we get \u200b characters in the response. That results in a lot of issues and above all it does not seem to server any purpose or make any sense. As simple example:
https://www.googleapis.com/language/translate/v2?key=YOURKEY&source=NL&target=EN&q=Hergeneer%20verkopen
returns:
{
"data": {
"translations": [
{
"translatedText": "Sell \u200b\u200bHerge Down"
}
]
}
}
Our software stumbles over these \u200b strings/characters and I have not found a way to prevent them or get rid of them.
Please read the documentation of the JSON format: https://json.org/
A string is a sequence of zero or more Unicode characters.
A char is either any Unicode character except " or \ or control-character,
[...]
or it is \u followed by four hex-digits.
We are in this last case, \u followed by four hex-digits, and it represents a Unicode character: Unicode Character 'ZERO WIDTH SPACE' (U+200B). It even has its own Wikipedia page: Zero-width space. And its Stack Overflow question: What's HTML character code 8203?.
Now, there are plenty Unicode characters with special behaviors, and this is one of those, an invisible one among others. So you need to be aware of how Unicode works, and you should sanitize input/output from third-parties API (and from user inputs as well).
Just define the list of characters that you actually want to support, and be sure to strip or filter out all the other ones. For instance, if you desire to support NL and EN, then you could strip what is outside the Latin script in Unicode.
Stripping the U+200B that you're encountering and other undesirable characters may save you from potential surprises like with:
big characters ⎲⎳
zalgo characters C̨̦̺̩̲̥͉̭͚̜̻̝̣̼͙̮̯̪o̴̡͇̘͎̞̲͇̦̲͞͡m̸̩̺̝̣̹̱͚̬̥̫̳̼̞̘̯͘ͅẹ͇̺̜́̕͢
invisible characters
emojis 👨‍👩‍👧‍👦#️⃣🏳️‍🌈

RegEx No Special characters

I am having allot of trouble finding a regex that will allow me to throw a error if the user tries to submit special characters especially "/" "\". I have a expression already that helps with other special characters but not the forward and backward slash Bonus: I don't want these ether but its not likely they will be entered. ~,!,#,#,$,%,^,&,*,().
I am currently using ^[\w{./\\(),'}+:?®©-]+$
The regex you have specifically allows / and \ (as well as ( and )). Change it like so:
^[\w{.,'}+:?®©-]+$
and keep removing any other characters you don't want to allow either.
In case you're wondering, the construct [...] is called a character class.
You can also use a negated character class like ^[^/\\()~!##$%^&*]*$ to allow any characters except /\()~!##$%^&*.

RegEx for Client-Side Validation of FileUpload

I'm trying to create a RegEx Validator that checks the file extension in the FileUpload input against a list of allowed extensions (which are user specified). The following is as far as I have got, but I'm struggling with the syntax of the backward slash (\) that appears in the file path. Obviously the below is incorrect because it just escapes the (]) which causes an error. I would be really grateful for any help here. There seems to be a lot of examples out there, but none seem to work when I try them.
[a-zA-Z_-s0-9:\]+(.pdf|.PDF)$
To include a backslash in a character class, you need to use a specific escape sequence (\b):
[a-zA-Z_\s0-9:\b]+(\.pdf|\.PDF)$
Note that this might be a bit confusing, because outside of character classes, \b represents a word boundary. I also assumed, that -s was a typo and should have represented a white space. (otherwise it shouldn't compile, I think)
EDIT: You also need to escape the dots. Otherwise they will be meta character for any character but line breaks.
another EDIT: If you actually DO want to allow hyphens in filenames, you need to put the hyphen at the end of the character class. Like this:
[a-zA-Z_\s0-9:\b-]+(\.pdf|\.PDF)$
You probably want to use something like
[a-zA-Z_0-9\s:\\-]+\.[pP][dD][fF]$
which is same as
[\w\s:\\-]+\.[pP][dD][fF]$
because \w = [a-zA-Z0-9_]
Be sure character - to put as very first or very last item in the [...] list, otherwise it has special meaning for range or characters, such as a-z.
Also \ character has to be escaped by another slash, even inside of [...].

Regular Expression Validator for Letters and Numbers only

What is the Regular Expression Validator for only Letters and Numbers in asp.net?
I need to enter only 0-9,a-z and A-Z. I don't want to allow any special characters single or double quotes etc. I am using asp.net 3.5 framework.
I tried ^[a-zA-Z0-9]+$ and ^[a-zA-Z0-9]*$. They are not working.
Any help will be appreciated.
Try the following.
^[a-zA-Z0-9]+$
go to this example and also alphanumerics for more
then try this
^[a-zA-Z0-9]*$
If length restriction is necessary use
^[a-zA-Z0-9]{0,50}$
This will match alphanumeric strings of 0 to 50 chars.
you can try this....
^[a-zA-Z0-9]+$
see more info at here
You can define a regular expression as follows,
Regex myRegularExpression = new Regex(" \b^[a-zA-Z0-9]+$\b");
be sure to include System.Text.RegularExpression
and then use the Regex to match it with your user-control as follows,
eg : if your user-control is a textbox
myRegularExpression.isMatch(myTextBox.Text);
Dear English speaking people. With all due respect. A-Z are not the only letters in the world. Please use \w instead of [A-Za-z0-9] if you support other languages in your apps

Regular Expression for username and password?

I am trying to use a regular expression for name field in the asp.net application.
Conditions:name should be minimum 6 characters ?
I tried the following
"^(?=.*\d).{6}$"
I m completely new to the regex.Can any one suggest me what must be the regex for such condition ?
You could use this to match any alphanumeric character in length of 6 or more: ^[a-zA-Z0-9]{6,}$. You can tweak it to allow other characters or go the other route and just put in exclusions. The Regex Coach is a great environment for testing/playing with regular expressions (I wrote a blog post with some links to other tools too).
Look at Expression library and choose user name and/or password regex for you. You can also test your regex in online regex testers like RegexPlanet.
My regex suggestions are:
^[a-zA-Z][a-zA-Z0-9._\-]{5,}$
This regex accepts user names with minimum 6 characters, starting with a letter and containing only letters, numbers and ".","-","_" characters.
Next one:
^[a-zA-Z0-9._\\-]{6,}$
Similar to above, but accepts ".", "-", "_" and 0-9 to be first characters too.
If you want to validate only string length (minimum 6 characters), this simple regex below will be enough:
^.{6,}$
What about
^.{6,}$
What's all the stuff at the start of yours, and did you want to limit yourself to digits?
NRegex is a nice site for testing out regexes.
To just match 6 characters, ".{6}" is enough
In its simplest form, you can use the following:
.{6,}
This will match on 6 or more characters and fail on anything less. This will accept ANY character - unicode, ascii, whatever you are running through. If you have more requirements (i.e. only the latin alphabet, must contain a number, etc), the regex would obviously have to change.

Resources