How to detect changes from Lowercase to Uppercase?
-
Hi Guys, I am using ASP.Net VB Coding. Does anyone of you knows how to detect changes from lowercase to uppercase or mixtures of lowercase and uppercase? Example: Textbox1.text = "Australia" was then changed to Textbox1.text = "AUstRALia" Looking at the example it shows here that the user was doing some text changes from "Australia" to "AUstRALia". Is there a way to check the changes of the textbox value? Thanks in advance Guys
hifiger2004
-
Hi Guys, I am using ASP.Net VB Coding. Does anyone of you knows how to detect changes from lowercase to uppercase or mixtures of lowercase and uppercase? Example: Textbox1.text = "Australia" was then changed to Textbox1.text = "AUstRALia" Looking at the example it shows here that the user was doing some text changes from "Australia" to "AUstRALia". Is there a way to check the changes of the textbox value? Thanks in advance Guys
hifiger2004
If you simply want to check the individual characters of the input string on the server, then something like the below would do the trick:
Dim fEmptyBefore As Boolean For Each ch As Char In stringInput If [Char].IsWhiteSpace(ch) Then fEmptyBefore = True Else If [Char].IsLetter(ch) Then If [Char].IsLower(ch) AndAlso fEmptyBefore Then ' We have a lower case letter at the start of a word Else If [Char].IsLower(ch) And Not fEmptyBefore Then ' We have an upper case letter in the middle of a word End If End If fEmptyBefore = False End If Next
You can then handle any instances where the casing is not as expected and take appropriate action. If you wish to validate / check the input on the client then there are ways to do this using JavaScript, but it would depend on what it is you are trying to achieve as to how you would approach the problem.Clean code is the key to happiness.
-
If you simply want to check the individual characters of the input string on the server, then something like the below would do the trick:
Dim fEmptyBefore As Boolean For Each ch As Char In stringInput If [Char].IsWhiteSpace(ch) Then fEmptyBefore = True Else If [Char].IsLetter(ch) Then If [Char].IsLower(ch) AndAlso fEmptyBefore Then ' We have a lower case letter at the start of a word Else If [Char].IsLower(ch) And Not fEmptyBefore Then ' We have an upper case letter in the middle of a word End If End If fEmptyBefore = False End If Next
You can then handle any instances where the casing is not as expected and take appropriate action. If you wish to validate / check the input on the client then there are ways to do this using JavaScript, but it would depend on what it is you are trying to achieve as to how you would approach the problem.Clean code is the key to happiness.
Yes I think this will help. What I am trying to do is to track the changes of a particular textbox in order to make the save button either enabled or disabled. And if the textbox value is "australia", then was changed to "AUSTRALIA" and then again was changed back to "australia" then in this case the save button should be in disabled state. Meaning nothing was changed. Thanks
hifiger2004
-
Yes I think this will help. What I am trying to do is to track the changes of a particular textbox in order to make the save button either enabled or disabled. And if the textbox value is "australia", then was changed to "AUSTRALIA" and then again was changed back to "australia" then in this case the save button should be in disabled state. Meaning nothing was changed. Thanks
hifiger2004
The best way to achieve this would be to use regular expressions through JavaScript. When the page loads you would save a global variable, or hidden field, that contains the value of the TextBox and on every keystroke within the TextBox, call a JS funtion that uses RegEx to determine whether the current value is different from the original. The original value would be used in the compilation of the expression. If you Google RegEx and JavaScript, there are plenty examples out there that will show you what is required. Basically, based on the result of the RegEx test you will get a boolean value telling you if the values are the same (case differences will be picked up) and you then enable / disable the Save button as required.
Clean code is the key to happiness.