I'm making a contact page so user's can send message to me when they want.
I got a textbox that they can put thire name, and regular expression to check if the name is in the correct form.
[אבגדהוזחטיכלמנסעפצקרשתץףןם\s\.]
My problem is that when I enter hebrew characters into the textbox its still don't recognize it and I get a validation error.
I tried the same regualr expression with an English unicode [a-zA-Z] and it work.
Do I need to add somthing to the .aspx page so it will "understand" that the input is in different language?
Perhaps the problem is that you only allow one character with your regular expression?
Try to change it to
[אבגדהוזחטיכלמנסעפצקרשתץףןם\s\.]*
Apart from that, I don´t think that you need to add any culture info to the page.
Related
I am trying to validate a textbox to ensure that it can only contain alphabetic characters and the characters "-" and "'", as it is for a name. I am trying to collect details that can be added into an account, so I want to collect all other fields and then at the end of the form a button is pressed and I would like the validation to be carried in a buttonclick event, instead of a textchanged event. I have tried other ways including using regular expressions but I have had the problem that it if I enter a letter and a number it sees this as valid.
Any help is much appreciated,
Thanks
use Regular Expressions:
bool IsValid = Regex.IsMatch(text, "^[a-zA-Z-']+$");
I have an XML file storing a string like the following:
Error: The form's name field was left empty!
Now, this message in the XML file is used in various locations. For instance, it is sometimes bound to an aspx control and sometimes displayed in a JavaScript alert.
In order to escape the single quote character, I modified the message as follows:
Error: The form\'s name field was left empty!
When the message is shown in a JavaScript alert, it is displayed as it should with the single quote escaped. However, when it is bound to an aspx control, it is displayed as is.
I tried modifying the message as follows:
Error: The form's name field was left empty!
and
Error: The form‘s name field was left empty!
With these two cases, the message displays as it should when bound to an asp control. However, when passed to a JavaScript alert, I get the ") expected" error in IE8.
How can I get this to work for both aspx controls and JavaScript alerts please? I have already wasted a lot of time on it. Thank you so much.
N.B. I am using a very old version of the .NET Framework, specifically 2.0.
You should just store your messages verbatim and then let each client handle the special character. So, store as Error: The form's name field was left empty! and then within each language add a step that checks for special characters and escapes them accordingly.
I have some text currently stored in my database table as nvarchar.
I am currently retrieving the text using a stored procedure and binding it to a literal within a gridview on the front end.
What I would like to do is to retrieve the text and then format it , like inserting line spaces and making
certain area bold. Is it possible to do so ? Can anyone give me an idea of how it can be done ?
One idea thats striking me is to use XML while storing the text . But even if I do that how would I make a certain part of the text bold and include line spaces.
So currently, my text is stored in the database table column nvarchar(max) as:
This is the heading this is the content
What I would like to do is to display the above within a gridview like:
**This is a Heading** (heading in bold)
This is the content
The simplest method (one I have used several times) is to store the html in the table like this:
<h1>This is the heading</h1>This is the content
You will have to add special handling for working with html, but it works just fine.
You can also store the header string in one field, and body in another.
Short of that, you would have to have some indicator telling the front which part of the string should be bolded, etc. and that can get very complex
Short answer is that this is possible but takes some work.
You first need to decide in what format are you going to store the data and how can you specify format on the client side, before text is entered into database.
If you have WYSIWYG editor for text – html conversion you can try storing the HTML. This will be the easiest way in terms of storage.
If you decide to use this method note that you’ll need to do a lot of validation on the server to avoid cross site scripting attacks. Shortly put – make sure the HTML you get on the server doesn’t contain any javascript or any tags apart from those you want to support.
Its better to use Editor of AJAX Toolkit, doesnt required any other thing, its a complete editor, you can even color your font as u wanted.
I need some help with a textbox:
The textbox is only allowed to contain letters.
how do I do this?
Check here : How to make Textbox only accept alphabetic characters, there are some different approached to choose from.
Edit: I see on the tags that we are talking asp.net, which the question I mentioned discusses the problem from a WinForms perspective. Might be that you want to do something similar using the onKeyPress event in JavaScript instead.
This article on w3schools.com contains an example code that may do exactly what you are looking for.
You can use regular expression validation for this and use following regular expression
"^[a-zA-Z]+$"
this is the easiest way to do this.
You could do this with javascript to filter out which charaters you accept, but if you can use Asp.net AJAX then you can add a FilteredTextBoxExtender to the textbox and only allow upper case and/or lower case letters.
To add a FilteredTextBoxExtender in Visual Studio 2008 you can do the following:
view the page in design mode and find the textbox
click the arrow on the right side of the textbox to open the TextBox Tasks menu and select Add Extender.
Then select the FilteredTextBoxExtender and click OK
Now your textbox should have a new property available in the designer. Make sure the textbox is selected and click F4 to open the properties designer.
Find the new property in the property designer. It should be named YOURTEXTBOXNAME_FilteredTextBoxExtender. Find the FilterType property and select UppercaseLetters or LowercaseLetters.
If you want both upper case and lower case letters you must edit the markup directly and set its value to "UppercaseLetters, LowercaseLetters"
Javascript/JQuery is your friend to make the UI only accept letters. However, you must make sure you validate the contents of the textbox on postback otherwise you can have bad data where people have bypassed the javascript.
I'm quite new to this:
I have created a simple form which contains a textbox and button and basically when the email address entered is correct, some results are shown below (this is using a gridview control).
What I am wanting to do is have some sort of email validation for the form - but have the validation placed within the page_load (within the button click) rather than the code behind the page itself.
I'm after a simple validation that checks an email has been entered otherwise display a popup and the email format is correct (abc#abc.com) in C#
I assume that the details will be displayed only when the buton is clicked ( form submitted) if so why not add a RegularExpression validator and map it to the text box. Then use the following regular expression to validate an email.
\b[A-Z0-9._%+-]+#[A-Z0-9.-]+\.[A-Z]{2,4}\b
This way it will increase user experience as well. The user does not have to wait for a post back to get the error alert.
Another regular expression for email format validation here.
This has been covered here.
Problem is there is no valid regex that covers the whole RFC 5322 grammar. All common regexes (like the one stated by Shoban) are too strict - example: the end part [A-Z]{2,4} that is supposed to cover the top level domain will tag .museum emails as invalid; but there are much more complex examples, like German Umlauts (vowel mutations) that have been allowed not too recently.
Our approach is to check for a superset rather than a subset of allowed emails in validation controls (like the one integrated integrated in Visual Studio that uses \w+([-+.']\w+)#\w+([-.]\w+).\w+([-.]\w+)* ) and deepen the check back on the server (maybe even use a webservice, like this one.
BTW, here is a better regex.