Hey

So i'm trying to create a pretty simple login for now...
When i click the Log On button i need it to ingnore the wheather the letters are uppercase or lowercase, in textbox1, how can i do that? :D

Kind Regards
-Jazerix

Dani AI

Generated

Short practical notes and pitfalls for a case-insensitive textbox login

For a reliable login experience, canonicalize both sides of the comparison and do the authoritative check on the server. Client-side normalization is fine for UX (auto-formatting, immediate feedback), but never trust it for authentication. Usernames are commonly treated case-insensitively; passwords usually are not.

Client-side (HTML / JavaScript) — a robust approach
Use Unicode normalization plus a locale-aware comparison so you handle non-ASCII characters correctly. Example that treats letters case-insensitively while preserving accent distinctions:

const input = document.getElementById('username').value.normalize('NFC');
const stored = dbUsername.normalize('NFC');

if (input.localeCompare(stored, undefined, { sensitivity: 'accent' }) === 0) {
  // consider equal (case-insensitive, accent-sensitive)
}

For simple ASCII-only checks a regex with the i flag works; remember to escape the stored string first:

function escapeRegExp(s) { return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); }
const re = new RegExp('^' + escapeRegExp(stored) + '$', 'i');
if (re.test(input)) { /* match */ }

Server/storage advice
Store a canonical form (normalized + casefolded) in the database for lookups, and keep the original for display. Alternatively, use a case-insensitive DB collation for username columns. For international input, prefer Unicode case-folding/normalization over ad hoc lowercasing to avoid surprises (Turkish dotted/dotless I, German ß, etc.).

Troubleshooting & reminders
As suggested, normalizing before comparing is a good start; ’s culture-aware warning is important—pick the right locale or case-fold algorithm for your user base. Trim whitespace, test with accented and special characters, and never rely only on client-side logic for authentication.

Useful references: String.prototype.localeCompare and String.prototype.normalize.

Recommended Answers

All 3 Replies

You can call TextBox1.Text.ToLower() or TextBox1.Text.ToUpper() so all characters are in lower or upper case.

as an addition to C#Jaap. if you want to then compare to another string (lets say username and password stored in database) and the char is not all upper/lower case use this:

string username = textbox1.text;
if (username.Equals("string from database", StringComparison.CurrentCultureIgnoreCase))
{
}

if you're using string in languages with special characters use InvariantCultureIgnoreCase

nice...///

Visit

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.