Solved

How to check for valid text input?

Posted on 1998-08-22
2
203 Views
Last Modified: 2010-03-04
Can someone help me with a Perl code to check for:

1. Valid text input (e.g. a person's name)

2. Valid text and numbers input (e.g an address)

I would like to use this in my form-processor. Thanks!
0
Comment
Question by:zgee
2 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1204455
1. a person's name may have numbers
2. an address may have no numbers

Unless the address is known to be in a specific area with specific rules for what is valis and what is not,
I don't see how you could check this in any language.
0
 
LVL 4

Accepted Solution

by:
mitek earned 10 total points
ID: 1204456
of course, it can be checked, and in any language
one way to do that in perl would be:

if ($name =~ /^[\w\'- ]+$/) {
  # valid name. it contains only letters, spaces, dashes and quotes (like, o'donnel)
}

if ($address =~ /^[\w\d\'\"- ]+$/) {
  # valid address. it contains letters, digits, spaces, dashes, single and double quotes
}

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sort hash by values desc 2 186
perl rename 2 142
.properties file to call function/method 9 59
Perl passing in variables to do substitution 6 66
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now