I am using a form wizard for step-by-step forms in our django application.
Now the requirement is to restrict chinese characters in the form fields. I managed to get the regex but the problem is if I try to use that validator regex on email field it doesnt allow '#' symbol, and raises invalid flag.
Here is the regex I am using:
restrict_chinese_characters_regex = RegexValidator(r'^[\u4E00-\u9FFF\u3400-\u4DFF\uF900-\uFAFF]*$', 'Chinese characters are restricted.')
I am kind of lost to make it work also with email field to allow '#' symbol.
Any ideas please?
Related
I have a Flutter TextFormField for email with input formatter as below.
var emailAddressFormatter = FilteringTextInputFormatter.allow(RegExp(
r"[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+#[a-zA-Z0-9]+\.[a-zA-Z]+"));
The problem is, when trying to input any character in the field it does not allow. The regex looks fine to me. When the formatter is removed the field accepts any character with any format. What am I going wrong?
The issue is that the FilteringTextInputFormatter that you're using rejects anything that does not match your regex. When you enter just a single character, it does not match your regex, so the character is rejected.
I know little about regex so I'm not sure if it's possible, but you would need a regex that would be able to match every string as you type e.g. a, am, amani#, amani#gmail.com.
I would personally not try to do filtering such as this. Instead, I would just allow all valid characters that are valid in email addresses to be present in the email and not enforce the specific format with the # and .. Then I would use a validator to check that the email is valid upon form submission.
If you don't like the alternate solution I proposed above and you can't use regex, you can make your own input formatter quite easily with TextInputFormatter.withFunction.
I have got a pattern to validate a HTML5 email field:
[A-z\u00c0-\u017e0-9._%+-]+#[A-z\u00c0-\u017e0-9.-]+\.[A-z]{2,3}$
It should allow European characters as well as numbers and other symbols.
I am getting this error:
A part followed by '#' should not contain the symbol 'á'
It allows abc#défg.com but not ábc#defg.com
Is anyone able to help? Thanks!
I have bee using model validation in asp.net MVC website.
I want to have a functionality to prevent user from entering whitespace in testbox and submit the form.
There are other validation attributes available, but i could not find any validation attribute that prevents user from entering only whitespace in the input textbox.
I could develop a custom attribute for this, but there is another method called regular expression validator which i think i could use easily to achieve this functionality.
For example: We can set an attribute that has a regular expression for validating email. if User enters wrong email, immediately a message is shown that email format is wrong.
I want use the same, but i don't know the regular expresison that validates a form input field if user enters only whitespace.
Please help me with this kind of regular expression?
Thanks,
[RegularExpression(#"[^\s]+")]
public string Data { get; set; }
Use Regex validation with this pattern:
^\S+$
This will allow only non-white-space.
(Update)
If you want users to enter whitespace but only if there are non-whitespace in there:
\S+
This regular expression might work
^[a-zA-Z0-9,-.#~!#$%&*<>?:;_='/()]+(\\s+[a-zA-Z0-9,-.#~!#$%&*<>?:;_='/()]+)*$
I try to use a RegexValidator with a CharField, but I can't make it work...
class Configuration(models.Model):
name = models.CharField(verbose_name=u'Name', validators =
[RegexValidator(regex="[a-z]", message="Not cool", code="nomatch")])
I then just register it with
admin.site.register(Configuration)
But then in the admin forms, it accepts any possible name... Is the validation system suppose to work like that, or am I missing something ?
Your current regex checks that your value contains a single character from a-z. So it allows a, but it also allows a1.
Try changing the regex to:
regex=r"^[a-z]+$"
By including ^ and $ to mark the beginning and end of string, you make sure that your string contains only characters from a-z. The + allows multiple characters.
Hi I want an entry in a form to start a specific way.
I want the entry to begin with "http:abc.com/w/" and there will have to be numbers and letters after. For example "http:abc.com/w/90765g5" is fine.
How do I set up a validation so that the user has to enter "http:abc.com/w/" in the start of the field?
Thanks
Mike
You'll need to use a regex validation, and write a custom regex to match the conditions you want:
validates :my_field, format: { with: /\Ahttp:abc\.com\/w\/([a-z0-9]*)\z/,
message: 'Please make sure it matches the right format'}
BTW, if you're on a mac, I highly recommend this app to help writing regexs: https://itunes.apple.com/au/app/patterns-the-regex-app/id429449079?mt=12